Revit Add-in Unit Testing

Here is a topic I have been flirting with for years, and never really got into seriously yet, except point to the efforts for unit testing in Revit 2011 by Rod Howarth and Daren Thomas back in 2010.

Finally, the cavalry is galloping in to our rescue in the shape of Steven Downing, Ali Talebi and Yamin Tengono of Arup.

They implemented a very complete and advanced unit testing system for Revit add-ins enabling NUnit as well as other test helpers like Moq to be used and including support for real-time addition of new tests, recompilation and reloading of add-ins, and re-running updated code and tests without restarting Revit.

The entire RvtUnit project including a sample project demonstrating its use is hosted on GitHub.

It includes a getting started document and a demonstration video showing the steps I just described:

I would suggest looking at the 2.5 minute demonstration video right away, first thing, to see the system in action and understand exactly what can be achieved and how:

Here is the detailed content of 'Getting Started.docx':

Introduction

RvtUnit is an example of how to achieve Unit Testing within Revit. By running the NUnit runner inside Revit, we can unit test code which relies on the Revit API, without having to wrap the entire Revit API.

The solution contains three projects:

RvtUnit solution projects

RvtUnit Project

SampleTool Project

Conclusion

Jeremy adds: Wow. I have nothing left to add. Almost.

The RvtUnit sample demonstrates a number of other important and exciting other features as well, such as support for multiple versions of Revit, ranging all the way from 2010 through 2014, so a thorough exploration of the source code provided is highly recommended.

To run and test this, you need to start up Revit properly, stand-alone, not in the debugger from within the Visual Studio IDE.

A huge thank-you to Steven, Ali and Yamin for this truly impressive framework!