Skip to content
Flying Animal

Easy Run Unit Test Revit With Visual Studio & Rider

🕒 Published at:

Introduction

Three years ago, I wrote an article about Revit Test Runner, which ended up being quite complicated. Today, I want to share a simpler approach to running unit tests for Revit projects using Visual Studio and Rider. This resource will be valuable if you are a Revit developer. Don't worry, I'll guide you through the process step by step.

Understanding this process is essential if you're a Revit developer. It will make your work more professional and efficient, ensure your code is clean, and maintain high quality.

I won't provide a detailed tutorial here, as it's available in the Readme. Instead, I'll help you understand how to customize it, encouraging you to follow the latest updates from the repository.

Visual Studio

With Visual Studio, you can use the NUnit Test Adapter extension to run unit tests for Revit projects. Here are the steps to do this, and fortunately, it's quite simple with the project provided by ricaun called RevitTest. Just follow these steps:

  1. Clone the RevitTest project:
bash
git clone https://github.com/ricaun-io/RevitTest.git
  1. Open the project in Visual Studio.
  2. Build the solution.
  3. Run the tests.

You should see the output like this:

If you want to interact with the currently open project in Revit, you need to change the path of the working project by modifying the FileName property in your test class:

csharp
protected override string FileName => @"<your path to the .rvt file>";

Make sure to replace "<your path to the .rvt file>" with the actual path to your Revit project file. This ensures that your tests will run against the correct Revit project file.

Rider

  1. In Rider, you can use the same GitHub project to run tests, but it requires a few additional configuration steps. Follow these instructions to set it up:

1.1 Open the project in Rider.

1.2 Navigate to File > Settings.

1.3 In the Settings menu, go to Unit Testing.

1.4 Enable the VS Code Adapter Support.

By following these steps, you will be able to run unit tests for Revit projects in Rider using the RevitTest project from GitHub.

  1. Change Build To Visual Studio Code (In Case .NET SDK not working)
  1. From tab Nunit, need change option Metadata to TestRunner :

Remember that you need Refresh Unit Test Tree to ignore case load duplicate if it exits.

  1. Here you go, you can run and testing your test :

In case make you confuse, you can follow the video step by step :

Conclusion

I hope in this post, will help you more intersecting and help improvement you process and have fun with develop something cool inside Revit.

And still have many resouce you can explore with recomend from author like :

Ricaun RevitTest - https://github.com/ricaun-io/RevitTest

Dynamo's Revit Tester Framework - https://github.com/DynamoDS/RevitTestFramework

Geberit's Revit Test Runner - https://github.com/geberit/Revit.TestRunner

Speckle's Revit Test Runner - https://github.com/specklesystems/xUnitRevit

NeVeSpl's RevitTestLibrary - https://github.com/NeVeSpl/RevitTestLibrary

Recenlly, I'm trying to understand what is meaning of life, and I founded a lot of interesting things. I will share with you soon.