Search code examples
c#revitrevit-api

Revit API Code Unit Testing


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.


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