Unit testing with Revit API
I've recently discovered the glory of unit testing...
My excuse for not doing it has always been that its too hard with the revit API. I'm wondering is there any methods anyone is using for doing this? Surely my unit tests could run from within revit as well.. I'd have to open a document, and then run the unit tests I guess.
I could manually make my own, but is there a way to use nUnit or something similar from within the revit API?
Re: Unit testing with Revit API
Fantastic tool for TDD isn't it? I use it every day. Personally don't use nUnit but it is a vital tool for API development and code documentation. Also try one of the mocking frameworks. This can be useful especially for early UI development if you are using a MVC design.
It's very hard for a number of reasons, the data is dynamic, the build/test/build cycle is non existent except in VSTA.
Not sure what you mean by manually making your own? It certainly would be very useful to be able to unit test in Revit wouldn't it... ;-)
Guy
Re: Unit testing with Revit API
I couldn't agree more!
We've done it sometimes in AutoCAD, when you could connect to AutoCAD and kick things off via COM.
I suspect that it's do-able via some kind of customization to NUnit or the VS2008 Test infrastructure - I just haven't had the time to chase it yet.
I'd imagine we'd need to define a Test Project ExternalCommand - then see if we could customize the behavior from there (or worse-comes-to-worst, just use reflection and DIY - as Rod mentioned).
-Matt
Re: Unit testing with Revit API
By the way - what unit testing framework do you guys prefer? NUnit?
I've used NUnit and MSTest a lot - and I've been meaning to look at xUnit.NET...
Just wondering if all of us use the same, so if one of us does have the chance to invent something, the others might share :)
-Matt
Re: Unit testing with Revit API
Quote:
Originally Posted by
mmason.65315
I'd imagine we'd need to define a Test Project ExternalCommand - then see if we could customize the behavior from there (or worse-comes-to-worst, just use reflection and DIY - as Rod mentioned).-Matt
If you want to use a unit testing for more than just testing libraries and do more TDD then you need a Build-Test-Build cycle or it's a waste of time. This is difficult on many levels. It's a hell of a lot of work regardless of which testing framework you choose. As a hint, I'd strongly recommend you don't roll your own testing framework and reflection is NOT your friend ;-)
Guy
Re: Unit testing with Revit API
Quote:
Originally Posted by
mmason.65315
By the way - what unit testing framework do you guys prefer? NUnit?
NUnit has come through for me on many a occassions. I like it better than Microsoft's testing framework.
Also I am hoping Autodesk guys will remove the GUI dependancy from the API sooner and life will be much better !
Prashant
Re: Unit testing with Revit API
Quote:
Originally Posted by
r.howarth
I've recently discovered the glory of unit testing...
welcome to the club ! :)
Quote:
Originally Posted by
r.howarth
My excuse for not doing it has always been that its too hard with the revit API. I'm wondering is there any methods anyone is using for doing this?
I agree with the hard to do with revit API part. My external commands usually just instantiate the objects in my application and hand over the data. Everything after that can be tested easily. Needless to say, I have my tests restricted to the functionality past the invoking of externalcommand. I kinda know what data I would want from the document and may have to create some for testing purposes.
My applications mostly read from the document and rarely push/move anything geometrically.
I would like to hear what you guys do!
Prashant
Re: Unit testing with Revit API
Quote:
Originally Posted by
ppathak
welcome to the club ! :)
I agree with the hard to do with revit API part. My external commands usually just instantiate the objects in my application and hand over the data. Everything after that can be tested easily. Needless to say, I have my tests restricted to the functionality past the invoking of externalcommand. I kinda know what data I would want from the document and may have to create some for testing purposes.
My applications mostly read from the document and rarely push/move anything geometrically.
I would like to hear what you guys do!
Prashant
Yeah that's probably the best option, most of my commands so far haven't been all that complex if you removed classes that are tightly coupled with the commandData though.
I've started using NUnit with Resharper(for in-Gui test window) on non-revit ASP.Net project I'm working on and love it.
What I was originally thinking in my initial post was to have the tests for my particular command running from inside revit, ie i start up a revit document and then run a macro which runs the tests, but theere'd be problems with the state of the commanddata object changing and it would be a pain to get working if its even possible.
Re: Unit testing with Revit API
I poked at it for a little bit last week, and made a bit of progress (having an ExternalCommand that runs the NUnit GUI - open source can be handy).
My next step though was to write an Extension class to implement a "RevitTest" - where the test method could have a signature which handed you the commandData object for your test (as well as doing various transactions, etc).
There are also a bunch of nasty issues with AppDomains and such, which I've worked around rather than resolved so far.
I'm not sure when I'll have time to take it further, though...
-Matt
Re: Unit testing with Revit API
Any further efforts on this front? Would like to be able to do this.
Sounds like what you're talking about would involve invoking the tests from within Revit? Or could Revit tests be initiated from outside?