CADbloke / CADtest

CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console
Other
36 stars 19 forks source link

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...

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