sweetfa
sweetfa

Reputation: 5845

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.

Upvotes: 3

Views: 3170

Answers (5)

ikeo
ikeo

Reputation: 21

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.

Upvotes: 2

Eric Anastas
Eric Anastas

Reputation: 22213

Jeremy Tammik wrote a blog post on this topic

http://thebuildingcoder.typepad.com/blog/2013/07/revit-add-in-unit-testing.html

Upvotes: 1

Matt
Matt

Reputation: 1096

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

Upvotes: 2

Victor Chekalin
Victor Chekalin

Reputation: 776

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.

Upvotes: 1

David Brown
David Brown

Reputation: 36239

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!

Upvotes: 1

Related Questions