Author Topic: CADtest - NUnit / Integration testing inside AutoCAD  (Read 8466 times)

0 Members and 1 Guest are viewing this topic.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
CADtest - NUnit / Integration testing inside AutoCAD
« on: March 10, 2015, 10:47:04 PM »
Following on from...
http://www.theswamp.org/index.php?topic=39236.0
http://www.theswamp.org/index.php?topic=47549.5
http://www.theswamp.org/index.php?topic=47110
http://ossandcad.blogspot.com.au/2009/04/mbunit-autocad-unit-testing-for-cad.html
http://www.theswamp.org/index.php?topic=46703
and lots of other links I've since lost...

CADtest is on Github.
CADtest runs NUnitLite version 3 inside AutoCAD and/or the AutoCAD Core Console. See My discovery post for a screenshot

I translated it to VB as well.

Your comments and contributions are most welcome
« Last Edit: March 15, 2015, 09:16:36 PM by CADbloke »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: CADtest - Unit / Integration testing inside AutoCAD
« Reply #1 on: March 10, 2015, 11:43:28 PM »
Thanks Ewen !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: CADtest - Unit / Integration testing inside AutoCAD
« Reply #2 on: March 10, 2015, 11:48:47 PM »
Yes, thanks indeed, nice job.
A lot of work there!
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CADtest - Unit / Integration testing inside AutoCAD
« Reply #3 on: March 11, 2015, 09:38:35 AM »
Cheers, I'm still going although I do have actual production work I should be doing whoops. I added a few dodgy SampleTests..cs|.vb. Curiously, running tests in accoreconsole.exe shows perfectly in version 2013 but has no console output in 2015...but running it in acad.exe v2015 is fine. In all cases it still writes TestResults.xml so it does actually work, you just can't see it in v2015's Core Console. Did they break it or is it just me? I even tried reinstalling AutoCAD.

The imaginatively named "Test_method_name()" is an example of why you may want to run a Unit...er, Integration test inside AutoCAD. once you start doing more complex things with objects the degree of difficulty in mocking or faking it anything is boringly high.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CADtest - Unit / Integration testing inside AutoCAD
« Reply #4 on: March 15, 2015, 06:07:36 PM »
If you are following this, keep an eye on the commits in the GitHub repo because this is still a work in progress...

My latest brainwave - the Test Method should not commit anything to the database, these are supposed to be Unit Tests (I am defining "Unit" here as a "Unit of work", not so much in the isolationist sense as the simplest possible unit of code) so the database should be clean for each test. I changed the sample test and also the Resharper test method templates. Note the helper methods that test Test Methods call still commit their Transactions but as the Helpers are called from inside the Test Method they will all be rolled back when the Test Method's transaction is rolled back.

As an aside, running tests in the Core Console of AutoCAD 2015 is a broken experience (they still run but the console output is broken) but ... I didn't break it, apparently.

As always, your observations and suggestions are encouraged!
« Last Edit: March 15, 2015, 09:18:48 PM by CADbloke »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #5 on: March 16, 2015, 09:39:07 AM »
I've not installed AutoCAD on the local machine, but I always use the remote debugging. Target remote machine has necessary installed AutoCAD versions (2009-2015) and Gallio. Usually, I write my Gallio-tests on the local machine (in the MSVS IDE) and save the result on the remote machine (the output path is the shared directory of the remote machine). Then I run this tests on the remote machine directly (through the Windows console), without any MSVS Remote Debugging Monitor and get the report in the HTML-format.

What software I must to install on the remote machine for testing through NUnit? I expect - I must install the NUnit - it is not a problem, but will be enough?


CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #6 on: March 16, 2015, 05:28:41 PM »
What software I must to install on the remote machine for testing through NUnit? I expect - I must install the NUnit - it is not a problem, but will be enough?
I haven't tried remote debugging yet - but I will!

You don't need to install NUnit on the remote machine -  the CADtest project at Github will get all the NUnit dependencies using Nuget and add them to the \bin\ folder. I have not installed NUnit 3 on my PC yet but CADtest runs ok. I have NUnit 2.6.4 installed and I know that version 2.x doesn't work in CADtest so I am sure it runs everything from the \bin\ folder.

NUnit's reporting format is XML but there are a few projects that convert it to HTML like https://github.com/SongArc/NUnit-HTML-Report-Generator/tree/develop and  https://github.com/relevantcodes/NUnitOrange or you can see the results in the console, even in acad.exe (but not theCore Console >v2013 because it looks like Autodesk broke it.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #7 on: March 19, 2015, 07:51:23 AM »
CADbloke, you are the best! I was looking your sample and created second template: AutoCAD .NET Extension (NUnit Tests). It is based on the AutoCAD .NET Extension template. I will send it on your email too. Now I am playng with it still.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #8 on: March 20, 2015, 02:38:18 PM »
Well... It is possible to write the tests and then compile this code for Gallio and NUnit without any changes - it works fine. It is like when we use the same code sources for building extensions of AutoCAD, nanoCAD and BricsCAD.

Tests, linked to Gallio framework works fine for any AutoCAD version (I checked for AutoCAD 2009 - 2015 x64 Enu).

Tests, linked to NUnit framework works fine for any AutoCAD version, newer than AutoCAD 2010. But at this case for AutoCAD 2011 - 2014 it is necessary to set the 0 as value for the NEXTFIBERWORLD variable and then restart AutoCAD. After finishing of testing, don't forget to set the 1 value for NEXTFIBERWORLD variable back.

It is impossible to use NUnit tests for AutoCAD older than 2011, because they has not NEXTFIBERWORLD variable. At this case it is possible only for Gallio.
« Last Edit: March 20, 2015, 02:56:00 PM by Andrey Bushman »

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #9 on: March 20, 2015, 07:51:39 PM »
I did not need to set NEXTFIBERWORLD to 0 (it is still 1 on my Dev machine). Did you set this attribute at the top of each test class?..
Code - C#: [Select]
  1. [TestFixture, Apartment(ApartmentState.STA)]
(ok, yes, I see that in your email, I will leave this tip here for others)

I have not yet tried to run any CADtests in AutoCAD versions other than 2013 & 2015, both in acad.exe and acadcoreconsole.exe.

I keep all my CADtests in a separate project which references my main project as a <ProjectReference Include="...">, I also keep all my normal NUnit tests in another separate project because I run those tests in Visual Studio. I know it sounds messy but I think it is tidier because I like things to be in their own place. It also means I can unload those projects from the Visual Studio solution if I don't want to work on them today.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #10 on: March 21, 2015, 12:58:23 AM »
Did you set this attribute at the top of each test class?..
Yes, I did.
I have not yet tried to run any CADtests in AutoCAD versions other than 2013 & 2015, both in acad.exe and acadcoreconsole.exe.
I tried to run with AnyCPU and acad.exe only. But I will try to do the same with x86|x64 and accoreconsole.exe surely.

I keep all my CADtests in a separate project which references my main project as a <ProjectReference Include="...">, I also keep all my normal NUnit tests in another separate project because I run those tests in Visual Studio. I know it sounds messy but I think it is tidier because I like things to be in their own place. It also means I can unload those projects from the Visual Studio solution if I don't want to work on them today.
You are right, I agree with you. My Idea was: the template has a "switcher" (property), which points a necessary result of building: either extension, or tests. I will do refactoring and create separate template instead of a single template which has all.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #11 on: March 25, 2015, 08:00:54 AM »
Gallio can create report in the XML or HTML format. NUnit create XML report only. But HTML would be convenient for reading...

I tryed to use some converters:

1. This application displays content of XML file as readable string in the console. It works, but I want to get HTML.
2. This application must generate HTML for our XML, but it creates an empty HTML.
3. This application crashes own process.

Maybe NUnitLite creates XML with other structure... So, it is necessary to write a converter XML -> HTML for NUnit output result.
« Last Edit: March 25, 2015, 08:14:40 AM by Andrey Bushman »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #12 on: March 25, 2015, 08:27:59 AM »
Ewen,

Entry Point doesn't work in Unit Tests projects, therefore I will exclude Entry Point from the AutoCAD .NET Extension Unit Tests template. NUnit and Gallio see Entry Point has not tests and they refuse to work with it.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #13 on: March 25, 2015, 08:56:31 AM »
Hi Andrey, just a quick response to your questions about HML reports - #3 is a bug in their app - See https://github.com/nunit/nunit/issues/525

I saw http://relevantcodes.com/nunit-orange-nunit-html-report-generator/ which I though it was nice but I think it had a couple of bugs. I did have a look but I didn't get too far. More later. Good night. :)


Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: CADtest - NUnit / Integration testing inside AutoCAD
« Reply #14 on: March 25, 2015, 09:10:22 AM »