This project demonstrates how to write and execute automated unit tests for AutoCAD drawings using:
-
accoreconsole.exeβ AutoCADβs headless scripting engine -
AutoCAD .NET API
-
AutoCAD 2026 (latest as of this writing β works for older and future releases too)
This project uses the following NuGet packages:
| Package | Version | Description |
|---|---|---|
NUnit |
4.3.2 | Latest NUnit framework for writing test cases. |
NUnitLite |
4.3.2 | Embedded lightweight runner to execute tests via AutoCAD Core Console. |
ExtentReports |
5.0.4 | Beautiful HTML test report generator integrated with the tests. |
AutoCAD.NET.Core |
25.1.0 | AutoCAD 2026 .NET API package for custom development and testing. |
β Note:
NUnitLiteis used to self-host and run the tests from insideaccoreconsole.exe, making the solution CI/CD friendly without needing an external test runner.
-
AutoCAD 2026 installed
-
Visual Studio 2022+ with desktop development workload
-
Access to required AutoCAD .NET reference assemblies (
acdbmgd.dll,acmgd.dlletc.)
Before building, make sure AutoCAD assemblies are referenced correctly in the .csproj.
git clone https://github.com/MadhukarMoogala/coreconsolerunner.git
cd coreconsolerunner
msbuild /t:build coreconsolerunner.slnThis project allows running NUnit-based unit tests against DWG files in three different ways:
| Case | Logic |
|---|---|
| 1. Core Console | Use /i argument passed via command line |
| 2. AutoCAD GUI, file open | Use active document path if available and saved |
| 3. AutoCAD GUI, no doc or unsaved | Prompt user to select a .dwg file for testing |
Best for CI pipelines and automation.
-
Ensure your DWG test file path is passed using the
/iswitch. -
Run the
accoreconsolewith a script file thatNETLOADs your DLL and runs theRunCADtestscommand.
accoreconsole.exe /i "D:\Tests\testdrawing.dwg" /s "TestRun.scr"TestRun.scr contents:
NETLOAD
D:\Path\To\Your\TestAssembly.dll
RunCADtests
QUIT
YRun tests on the currently opened DWG file in the AutoCAD GUI.
-
Open your DWG file in AutoCAD.
-
Load your test DLL using
NETLOAD. -
Run the command:
Command: RunCADtestsIf no document is open, AutoCAD will prompt the user to select a .dwg file for testing.
-
Start AutoCAD.
-
NETLOADyour DLL. -
Run the command:
Command: RunCADtests
-
A file dialog will appear asking for a DWG file.
-
After selection, tests will be run against that file in an off-screen side database.
- Running in
accoreconsole.exewithRunTests.bat
RunTests.bat
Current dir is now: D:\Work\repo\CoreConsoleTestRunner
Using accoreconsole at: D:\ACAD\watt\AutoCAD 2026\accoreconsole.exe
Running in AutoCAD mode...
Redirect stdout (file: C:\Users\moogalm\AppData\Local\Temp\accc315322).
AcCoreConsole: StdOutConsoleMode: processed-output: enabled,auto
AutoCAD Core Engine Console - Copyright 2025 Autodesk, Inc. All rights reserved. (W.74.0.0)
Execution Path:
D:\ACAD\watt\AutoCAD 2026\accoreconsole.exe
Current Directory: D:\Work\repo\CoreConsoleTestRunner
Version Number: W.74.0.0 (UNICODE)
LogFilePath has been set to the working folder.
Regenerating model.
Drawing created using acadiso.dwt from AutoCAD profile: <<Unnamed Profile>>
**** System Variable Changed ****
1 of the monitored system variables has changed from the preferred value. Use SYSVARMONITOR command to view changes.
AutoCAD menu utilities loaded.
Command:
Command:
Command:
Command: SECURELOAD
Enter new value for SECURELOAD <0>: 0
Command: netload Assembly file name: "D:\Work\repo\CoreConsoleTestRunner\CoreConsoleRunner\bin\x64\Debug\net8.0-windows\win-x64\CoreConsoleRunner.dll"
Command: RunCADtests
Running NUnit tests...
Invalid or missing drawing path:
Command: QUIT
_Y
Really want to discard all changes to drawing? <N> _Y
Command:
QUIT
LogFilePath has been restored to ''.
Exit Code: 0
- Running from AutoCAD GUI
-
XML results saved to:
TestResult.xml -
Optional: Generate HTML reports using:
To add a new AutoCAD entity test, create a class under the Tests/ folder using the same pattern as existing ones. Each test class must:
-
Inherit from
DrawingTestBase -
Be decorated with
[TestFixture, Apartment(ApartmentState.STA), Category("EntityName")]
π Example: LineTests
[TestFixture, Apartment(ApartmentState.STA), Category("Line")]
public class LineTests : DrawingTestBase
{
private Line _line;
public void GetFirstLine()
{
if (_line != null) return;
var modelSpace = (BlockTableRecord)trans.GetObject(
SymbolUtilityServices.GetBlockModelSpaceId(testDb),
OpenMode.ForRead);
foreach (ObjectId entId in modelSpace)
{
if (entId.ObjectClass.Name == "AcDbLine")
{
_line = trans.GetObject(entId, OpenMode.ForRead) as Line;
break;
}
}
if (_line == null)
Assert.Fail("No line entity found in ModelSpace.");
}
[Test]
public void LineLengthTest()
{
GetFirstLine();
var test = TestReport.Extent.CreateTest(nameof(LineLengthTest));
Assert.That(_line.Length, Is.EqualTo(100).Within(0.001));
test.Pass($"Length: {_line.Length}");
}
[Test]
public void LineStartPointTest()
{
GetFirstLine();
var test = TestReport.Extent.CreateTest(nameof(LineStartPointTest));
Assert.That(_line.StartPoint, Is.EqualTo(new Point3d(0, 0, 0)).Using<Point3d>((a, b) => a.IsEqualTo(b, new Tolerance(1e-6, 1e-6)) ? 0 : 1));
test.Pass($"Start Point: {_line.StartPoint}");
}
}-
accoreconsole.exeis headless: ideal for CI/CD pipelines and regression testing. -
Ensure that
SECURELOADis set to0in script to allow.dllloading. -
Tests can inspect entities (e.g.
Circle,BlockReference) using AutoCAD API.
This project is inspired by:
- CADbloke/CADtest
CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console.
Highly recommended resource for plugin-level unit testing:
- AutoCAD/Civil 3D Plugin Unit Test with NUnit β Civil WHIZ
A helpful guide on structuring NUnit-based tests in the context of AutoCAD and Civil 3D.](https://civilwhiz.com/docs/autocad-civil-3d-plugin-unit-test-with-nunit/)
Madhukar Moogala
Developer Advocate


