Why Unit Test AutoCAD Code?
If you’re developing on the AutoCAD .NET API (AcDb managed layer)—handling things like blocks, entities, transactions, dynamic properties, or geometry—you probably want:
- Inspires confidence that your logic works across DWG files
- Repeatable tests that run in isolation
- Fast feedback without relying on GUI interaction
That’s exactly what this project enables.
This is not for UI-level testing (dialogs, palettes, CUI). It’s for AcDb-level logic.
What This Project Enables
This project shows how to:
- Run unit tests on DWG files via
accoreconsole.exe - Use NUnit/NUnitLite to test AutoCAD logic like circles, lines, blocks, and more
- Generate HTML reports with ExtentReports
- Run tests in:
- AutoCAD GUI (on active or selected DWG)
- AcCoreConsole (headless)
- Side databases (for isolated testing)
How It Works
Tests inherit from a base class DrawingTestBase, which handles:
- Opening a DWG (via command-line args or prompt)
- Creating transactions
- Managing AutoCAD
Databaseinstances - Detecting whether running inside
accoreconsole.exeor full GUI
You trigger tests using the RunCADtests command, either:
In AcCoreConsole:
accoreconsole.exe /i sample.dwg /s TestRun.scr
In AutoCAD GUI:
NETLOAD your test DLL
Command: RunCADtests
→ Optionally select a drawing if one isn't open
→ Tests run and output an HTML report
Sample Test
Here’s a basic test for verifying a circle’s radius:
[TestFixture, Apartment(ApartmentState.STA)]
public class CircleTests : DrawingTestBase
{
[Test]
public void CircleRadiusTest()
{
var circle = GetFirstCircle();
Assert.That(circle.Radius, Is.EqualTo(50));
}
}
You can write similar tests for:
- Blocks (dynamic/static)
- Line geometry
- Property evaluation
- Transaction behavior
Project Structure
/Tests: Place test classes here (CircleTests.cs,LineTests.cs, etc.)/TestInfrastructure: Contains base classes and utilities/TestRun.scr: AutoCAD script to load and invoke testsRunTest.bat: Launchesaccoreconsolewith a selected DWG and script
Getting Started
git clone https://github.com/MadhukarMoogala/coreconsolerunner.git
cd coreconsolerunner
msbuild /t:build coreconsolerunner.sln
Modify the script/batch to point to your DWG and test assembly. Run using accoreconsole or AutoCAD
GUI.
Inspired By
Special thanks to:
Footnote
This approach makes it easier to bring modern testing practices to AutoCAD plugin development—
especially AcDb logic. If you’re building custom entities, automations, or design validations, give
this a try.

Leave a Reply