Writing Unit Tests for Custom Commands

Writing Unit Tests for Custom Commands

oneMSN
Advocate Advocate
3,272 Views
3 Replies
Message 1 of 4

Writing Unit Tests for Custom Commands

oneMSN
Advocate
Advocate

I wondered if anyone has any thoughts on how we can write unit test for AutoCAD command that we write for a plugin.

Currently I just run up in debug, try my command and see that it does what I expect it should.

 

has anyone ever written unit tests for their commands.  How did you get round dependency on AutoCAD objects?

 

Just looking to see if this is possible.

0 Likes
Accepted solutions (2)
3,273 Views
3 Replies
Replies (3)
Message 2 of 4

FRFR1426
Collaborator
Collaborator
Accepted solution

Please look at this post for integration tests. The development of the Gallio AutoCAD extension seems to be stopped at AutoCAD 2013, so you'll have to make an upgrade yourself. The source code can be found here: https://github.com/Gallio/mbunit-v3/tree/master/src/Extensions/AutoCAD.

 

You can run some unit tests by setting your project output path to the installation directory of AutoCAD, but this approach is very limited and not very clean because you will pollute your AutoCAD installation.

 

The best approach is to find a way to integrate a test runner in AutoCAD. You can write your own runner/test framework like this one for Revit: https://github.com/DynamoDS/RevitTestFramework or use an existing framework like NUnit and make the test runner work in AutoCAD like this project, also for Revit: https://github.com/ArupAus/RvtUnit

 

It is not an easy task as you can see. And you need to start AutoCAD each time you want to run the test (you can speed up the process if you use AutoCAD Core Console however).

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 4

CADbloke
Advocate
Advocate
Accepted solution

https://github.com/CADbloke/CADtest runs NUnit inside AutoCAD.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 4 of 4

soonhui
Advisor
Advisor

Shameless plug, I've written a detailed post on how I get NUnit to run with Civil 3D/AutoCAD, based on @CADbloke very helpful guide. 

##########

Ngu Soon Hui

##########

I'm the Benevolent Dictator for Life for MiTS Software. Read more here


I also setup Civil WHIZ in order to share what I learnt about Civil 3D