RevitTestLibrary.MSTest
0.3.1.2025
See the version list below for details.
dotnet add package RevitTestLibrary.MSTest --version 0.3.1.2025
NuGet\Install-Package RevitTestLibrary.MSTest -Version 0.3.1.2025
<PackageReference Include="RevitTestLibrary.MSTest" Version="0.3.1.2025" />
paket add RevitTestLibrary.MSTest --version 0.3.1.2025
#r "nuget: RevitTestLibrary.MSTest, 0.3.1.2025"
// Install RevitTestLibrary.MSTest as a Cake Addin
#addin nuget:?package=RevitTestLibrary.MSTest&version=0.3.1.2025
// Install RevitTestLibrary.MSTest as a Cake Tool
#tool nuget:?package=RevitTestLibrary.MSTest&version=0.3.1.2025
Warning Since version v.0.1 the RTL switched to .net 8 (Revit 2025), any further development on .net framework 4.8 (Revit 2023, 2024) is not planned.
RevitTestLibrary (RTL)
Proof of Concept that it is possible to run and debug unit tests in Visual Studio with remote execution inside Revit.
Origin
There are three established solutions for unit testing in Revit space, but none of them is integrated with the IDE. This makes them good mostly for detecting regressions, which makes QA happy. We, developers, love and need unit tests for different reasons. There is no better way of writing a code, than running a small fragment of it in isolation without the need to start the whole (big (and slow)) application. We need as fast feedback loop as possible. <h4 align="center"> Red, Green, Refactor, Repeat </h4>
Features
- does not keep dlls locked after conducting a unit test, which means Revit does not have to be closed down in order to recompile dlls
- gives full access to the exception stack trace with interactive links
- allows to mix unit tests that are run inside Revit context with tests that can be run without Revit context
- unit tests are run in a special instance of Revit that does not load any addins.
Getting started
- Add information about Revit location to
.runsettings
file. How to use.runsettings
on Microsoft learn.
<RunSettings>
<MSTest>
<AssemblyResolution>
<Directory path="D:\Autodesk\Revit 2025\" includeSubDirectories="false"/>
</AssemblyResolution>
</MSTest>
</RunSettings>
- Install nuget
https://www.nuget.org/packages/RevitTestLibrary.MSTest
- Change test method attribute to
[RevitTestMethod]
and add one input parameter of typeRevitContext
- Add the RevitPath attribute
[assembly: RevitPath("D:\\Autodesk\\Revit 2025\\Revit.exe")]
.
using System;
using System.IO;
using Autodesk.Revit.DB;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RevitTestLibrary;
[assembly: RevitPath("D:\\Autodesk\\Revit 2025\\Revit.exe")]
namespace RevitTestLibrary.Demo.MSTestV3
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod_WriteLine()
{
Console.WriteLine("This is a standard test");
}
[RevitTestMethod]
public void Revit_TestMethod_WriteLine(RevitContext context)
{
Console.WriteLine("This code is running inside Revit.");
}
}
}
Demo
The Demo project is available here: RevitTestLibrary.Demo.MSTestV3
Current limitations
- works only with : Revit 2025 and Visual Studio 2022
- theoretically, it can be used with any test framework, but right now only integration with MSTest v3 is available
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- MSTest.TestFramework (>= 3.2.2)
- RevitTestLibrary (>= 0.3.0.2025)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on RevitTestLibrary.MSTest:
Repository | Stars |
---|---|
NeVeSpl/RevitDBExplorer
Interactive Revit database exploration tool to view and edit BIM element parameters, properties and relationships.
|
Version | Downloads | Last updated |
---|---|---|
0.4.0.2025 | 165 | 3/29/2024 |
0.3.1.2025 | 87 | 3/27/2024 |
0.3.0.2025 | 86 | 3/27/2024 |
0.2.0.2025 | 90 | 3/26/2024 |
0.1.2.2025 | 96 | 3/24/2024 |
0.0.6 | 456 | 4/10/2023 |
0.0.5 | 383 | 1/31/2023 |