Skip to content

CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console

License

Notifications You must be signed in to change notification settings

CADbloke/CADtest

Repository files navigation

CADtest for NUnit by@CADbloke

CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console

This project is only possible because of all the hard work done over the years by Charlie Poole and the NUnit team, this is 99.999% their work, all I did was plug it in to AutoCAD.

If you're a Revit user - check out https://github.com/DynamoDS/RevitTestFramework

Join the chat at https://gitter.im/CADbloke/CADtest

My Thanks and Kudos also go the the ever-resourceful AutoCAD developer crowd at The Swamp and the Autodesk forums and to @phliberato for his contributions.

Getting Started

This is meant to be a how-to example rather than a full implementation that you can just drop more tests into. Take a look at the code and how it works, take what you like and ignore what you don't.

You will, of course, need AutoCAD installed to use this. No, it won't work in AutoCAD LT, Yes, it should work in NanoCAD, BricsCAD etc. with the right references, I am yet to try that, if you do, please let us know how you go.

Open the Visual Studio 2013 Demo solution to see how this works. You may want to change the AutoCAD Project references - It is currently set to build AutoCAD 2016 and .NET 4.5, getting the references from Nuget. There are projects for other versions of AutoCAD in there too, they will need some tweakage to get working.

The first build should fetch the Nuget packages. If the second build fails, restart Visual Studio or close the Solution and re-open it, I don't think it loves mixed C# & VB Solutions.

To add the NUnitLite v3 Console runner to a Visual Studio project...
  • There are folders for C# and VB projects. This was originally written in C# and converted to VB at http://converter.telerik.com/ so the VB code may look a bit too much like C# for your liking, it also may occasionally be missing updates that the C# code has because getting old absent minded.
  • Clone this repo to your local Library folder
  • Add a new class library project to your Solution
  • In Nuget, add NUnitLite 3 and the NUnit 3Framework to your new class library - congratulations, it is now a test project. If it already was an NUnit 2.* Test project then replace it with NUnit 3. You may have to fix a few things. Such is life in an ever-changing world.
  • If you want to modify any CADtest code files you should copy them into your project which you can do by "Add Existing Item" and not linking it. Me, I generally link to them from a local library Repo by hand-editing the CSPROJ file but I like breaking things. How do you tihnk I discovered this?
  • To link them from your local library, hand-edit your .CSPROJ | .VBPROJ file (see below)
  • link or copy App.cs | app.vb, it has the code to display the console
  • link or copy CADtestRunner.cs | CADtestRunner.vb and tweak it as you wish, it launches NUnitLite and runs the tests. You can set all sorts of options there.
  • If you edit an original file linked from your library beware that this will affect everything else that links to it.
  • If you don't link to an original then you may need to edit a lot of projects if this gets updated and you want to use the updates.
  • You can set the Debug startup to run a .SCR file to netload the DLL and run the command. the .SCR file would look a lot like...
netload "C:\Path\To\Your\TestDLL.dll"
RunCADtests

The startup parameters in Visual Studio's Debug settings would look like for AutoCAD...

/b C:\Path\To\Your\TestNetload.scr

... and for the Core Console like...

/s C:\Path\To\Your\TestNetload.scr

because why should they be the same that would be /b/s.

  • Ctrl-F5 runs the startup project without debugging so if you set your CADtest project as the startup that will run your tests by netloading the DLL and running the command.
  • This is really fast in the Core Console runner. If you are using the Core Console then Define a Build Constant "CoreConsole" and don't reference AcMgd.dll
  • If you have Resharper and are using C# then you can add the Resharper Templates file to one of the local solution layers in Resharper Options manager. The file is ResharperCADtestTemplates.DotSettings - it only has C# templates in it, sorry VB'ers.

Linking the C# code files by editing .CSPROJ

In the CSPROJ file, if you want to copy and modify the Command class...

<Compile Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-CS\**\*.cs" Exclude = "\CADtestRunner.cs>

... and then add CADtestRunner.cs to the project as an existing item but don't link to it.

or if you want to keep it as-is...

<Compile Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-CS\**\*.cs">

...and this is the rest of the copy-paste into the CSPROJ...

  <Link>CADtest\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
<None Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-CS\**\*.txt">
  <Link>CADtest\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>

Linking the VB code files by editing .VBPROJ

In the VBPROJ file, if you want to copy and modify the Command class...

<Compile Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-VB\**\*.vb" Exclude = "\CADtestRunner.vb>

... and then add CADtestRunner.vb to the project as an existing item but don't link to it.

or if you want to keep it as-is...

<Compile Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-VB\**\*.vb">

...and this is the rest of the copy-paste into the VBPROJ...

  <Link>CADtest\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
<None Include="$(Codez)\your.Libraries\AutoCAD\CADtest\CADtest-VB\**\*.txt">
  <Link>CADtest\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>

ProAmTips

In the Test Classes, use the Attribute [TestFixture, Apartment(ApartmentState.STA)](C#) or <TestFixture, Apartment(ApartmentState.STA)>(VB) ...especially for AutoCAD 2015 because it throws exceptions otherwise.

Suggestions, questions and contributions are most welcome, use the Issues here or feel free to submit a pull request or ten, it's open source so it's for all of us.

Cheers Ewen

About

CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages