NUnit
Run NUnit tests inside a live Revit or AutoCAD-based host through Microsoft Testing Platform (MTP).
- Framework: NUnit
5.0.0, the default engine - Adapter:
RevitDevTool.TestAdapter0.1.4 - Other frameworks: TUnit and MSTest are opt-in
Project setup
Add the adapter and NUnit to the test project:
<PropertyGroup>
<HostName>Revit</HostName>
<HostVersion>2025</HostVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RevitDevTool.TestAdapter" Version="0.1.4" />
<PackageReference Include="NUnit" Version="5.0.0" />
<PackageReference Include="Nice3point.Revit.Toolkit" Version="2025.*" />
</ItemGroup>
Create global.json beside the test .csproj so the project uses Microsoft Testing Platform:
{
"sdk": { "version": "10.0.0", "rollForward": "latestMinor" },
"test": { "runner": "Microsoft.Testing.Platform" }
}
HostName and HostVersion are required. For the full list of host names and the optional launch and timeout settings, see Host settings.
- The adapter is MTP-native. Do not add
NUnit3TestAdapter,Microsoft.Testing.Extensions.VSTestBridgeor a.runsettingsfile. - Do not set
<RuntimeIdentifier>on net8 or net10. - On net48, set
win-x64only when the SDK needs it for an x64 executable. The package flattens testhost output, so a leftover RID does not nest underwin-x64.
Writing tests
Use normal NUnit attributes such as [TestFixture], [Test], [SetUp] and parameterized cases. Tests run in host context, so document access, transactions, selection and UI-thread rules still apply.
using Nice3point.Revit.Toolkit;
[TestFixture]
public sealed class HostTests
{
[Test]
public void Revit_application_is_available()
{
Assert.That(RevitContext.Application, Is.Not.Null);
}
}
It brings the Revit API references and RevitContext (Application, UiApplication, ActiveDocument, ActiveView), and it works well with .NET Revit test projects. See RevitToolkit.
Running
dotnet test --project .\MyHostTests.csproj -c Debug --filter Revit_application
- Run it from the test project directory, where
global.jsonand the.csprojlive. --filtertakes a method name or a substring of one.--list-testsshows the discovered tests.- Set
<ForceLaunch>true</ForceLaunch>in the project when you need a fresh host.
Debugging and troubleshooting
Attach Visual Studio, Rider or C# Dev Kit to the Autodesk host process before running a test when you need to debug host API code. See Attach Debugger.
| Symptom | Check |
|---|---|
| Zero tests discovered | MTP packages and NUnit references are present; no VSTest adapters |
| Host does not start | HostName, HostVersion, installation path and LaunchTimeout |
| Test times out | Modal dialogs, document state and PerTestTimeout |
| API call fails | The test runs inside the expected host and target framework |
See Testing Overview for the shared pipe and lifecycle model.