Question

Is it possible to create unit tests of my own Revit API code that interacts with a Revit DB model without having Revit running.

If so, how might this be achieved.

Was it helpful?

Solution

I've been involved with some of the threads that are mentioned. I've even worked on a project that had a very well developed unit testing framework for Revit (which unfortunately I can't share).

But here's what I can tell you about the approach: You need to build your own basic framework for executing tests. It runs as an Addin inside of Revit (you have to start Revit, choose the Addin, and then choose the test harness assembly to run). After that, it's much like xUnit, MSTest, etc. I think we had some additional test attributes that even pointed each test to a particular test model.

The hassle in the whole thing is that you have to start Revit up, which as you know can take some time (and makes the process a lot less convenient than using unit testing in traditional development). Until Autodesk decides to open things up more, that's what you're stuck with (unless you go with the "Revit Python Shell" approach... I guess I was referring only to traditional .NET languages).

Good Luck...

OTHER TIPS

The Dynamo project includes the Dynamo Revit Test Framework, which is allows you to run NUnit tests on the Revit API. It handles the generation of journal files to create individual Revit sessions to tests in isolation (tests can also be run together as a fixture in one revit session). It's geared towards Dynamo presently, but would be easy to adapt for non-Dynamo use. And it is open source as part of the Dynamo project.

Also, if you make improvements to the source, please feel free to make a pull request. We're always looking for good contributions.

You could abstract your API code into an interface, then implement it on a set of mock objects to use for testing:

Unit Testing: Mock Objects to the Rescue!

I'm not sure you find more about Revit unit testing than described here http://forums.augi.com/showthread.php?98536-Unit-testing-with-Revit-API and here http://darenatwork.blogspot.com/2010/11/unit-testing-revit-plugins_10.html

Or may be you find your own way how to use unit tesing with Revit API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top