Speckle Blog / xUnitRevit: a test runner for Revit

Unit tests are one of those things in life that you try to avoid for as long as you can but, eventually, you surrender to and start to accept. With the release of Speckle 2.0 we're aiming at >90% test coverage, and we are doing everything we can to get there. This is why we developed a set of open source tools to help us run unit tests inside Revit.


This is a companion discussion topic for the original entry at https://speckle.systems/blog/xunitrevit
2 Likes

Yay, we got comments now :slight_smile:

1 Like

Great stuff. There and back again :smiley:

Very nice stuff, thank you! Will do some testing with this in the future. For now, one very minor comment: several links in the blog are not working because they contain an h to much in the beginning (so hhttps instead of https).

2 Likes

Thanks for reporting! Guess that was a find and replace fail on my end :slight_smile: fixed!

2 Likes

Thank you very much for this guys, I have been using xUnit for the last couple of weeks and it works great. I wasn´t doing any unit testing until now but thanks to this tool all the stuff I am developing for Revit is much more stable and reliable.

2 Likes

So glad you’re finding it useful Palatino! Unit testing can be a bit tedious sometimes, but it definitely helps you push changes with confidence and saves time in the long run :sparkles:

2 Likes

Hi guys,

xUnitRevit looks and works great thank you for sharing that!

I was looking at the code and was wondering if you ever got it to work by loading the test assembly in a separate AppDomain? Thereby allowing the test assembly to be unloaded. This would make it possible to change the test code, rebuild the test assembly and start the new tests without restarting Revit.

I tried to create my own Revit test runner when I started using Speckle and Revit more than a year ago, but was not able to integrate existing test runners (like xunit/nunit) and load the test assembly into a separate AppDomain.

I gave up and ended up using a different approach: I created my own .Net Test Attributes and run methods marked with these attributes using reflection. I also used Assembly.Load(byte[] assembly) to not lock the test assembly. My test tool has limited functionality and works with quirks (for loading SqlLites’ x86/x64 assemblies) so I would rather be using xUnitRevit.

1 Like

Hey @fmeijer , welcome&thanks :slight_smile: !

AFAIK, Revit can only load plugins/assemblies in its AppDomain so this is not possible.

The good thing is that starting from ~Revit 2020 you can use “stop and continue” directly from VS in most circumstances, allowing you to tweak the code a bit and continue debugging without restarting Revit.