Nice3point.TUnit.Revit
2026.0.1
Prefix Reserved
dotnet add package Nice3point.TUnit.Revit --version 2026.0.1
NuGet\Install-Package Nice3point.TUnit.Revit -Version 2026.0.1
<PackageReference Include="Nice3point.TUnit.Revit" Version="2026.0.1" />
<PackageVersion Include="Nice3point.TUnit.Revit" Version="2026.0.1" />
<PackageReference Include="Nice3point.TUnit.Revit" />
paket add Nice3point.TUnit.Revit --version 2026.0.1
#r "nuget: Nice3point.TUnit.Revit, 2026.0.1"
#:package Nice3point.TUnit.Revit@2026.0.1
#addin nuget:?package=Nice3point.TUnit.Revit&version=2026.0.1
#tool nuget:?package=Nice3point.TUnit.Revit&version=2026.0.1
Testing Framework for .Revit
Write unit tests for your Revit add-ins using the TUnit testing framework with source-generated tests, parallel execution, and Native AOT support.
Installation
You can install the Toolkit as a NuGet package.
The packages are compiled for specific versions of Revit. To support different versions of libraries in one project, use the RevitVersion
property:
<PackageReference Include="Nice3point.TUnit.Revit" Version="$(RevitVersion).*"/>
The public version of this package does not contain implementation for the framework. An open source version is not currently planned due to Autodesk export regulations.
Writing your first test
Start by creating a new class inheriting from RevitApiTest
:
public class MyTestClass : RevitApiTest
{
}
Add a method with [Test]
and [TestExecutor<RevitThreadExecutor>]
attributes:
public class MyTestClass : RevitApiTest
{
[Test]
[TestExecutor<RevitThreadExecutor>]
public async Task MyTest()
{
}
}
This is your runnable test. The [TestExecutor<RevitThreadExecutor>]
attribute ensures the test executes within Revit's single-threaded API context.
Running your tests
TUnit is built on top of the Microsoft.Testing.Platform. Combined with source-generated tests, running your tests is available in multiple ways.
dotnet run
For simple project execution, dotnet run
is the preferred method, allowing easier command line flag passing.
cd 'C:/Your/Test/Directory'
dotnet run -c "Release R26"
dotnet test
dotnet test
requires the configuration to target the desired Revit version.
cd 'C:/Your/Test/Directory'
dotnet test -c "Release R26"
dotnet exec
If your test project has already been built, use dotnet exec
or dotnet
with the .dll path:
cd 'C:/Your/Test/Directory/bin/Release R26/'
dotnet exec YourTestProject.dll
or
cd 'C:/Your/Test/Directory/bin/Release R26/'
dotnet YourTestProject.dll
Application testing
Test Revit application-level functionality:
public sealed class RevitApplicationTests : RevitApiTest
{
[Test]
[TestExecutor<RevitThreadExecutor>]
public async Task Documents_Startup_IsEmpty()
{
var documents = Application.Documents.Cast<Document>();
await Assert.That(documents).IsEmpty();
}
[Test]
[TestExecutor<RevitThreadExecutor>]
public async Task Create_XYZ_ValidDistance()
{
var point = Application.Create.NewXYZ(3, 4, 5);
await Assert.That(point.DistanceTo(XYZ.Zero)).IsEqualTo(7).Within(0.1);
}
}
Document testing
Test document-specific operations with setup and cleanup:
public sealed class RevitDocumentTests : RevitApiTest
{
private static Document _documentFile = null!;
[Before(Class)]
[HookExecutor<RevitThreadExecutor>]
public static void Setup()
{
_documentFile = Application.OpenDocumentFile($@"C:\Program Files\Autodesk\Revit {Application.VersionNumber}\Samples\rac_basic_sample_family.rfa");
}
[After(Class)]
[HookExecutor<RevitThreadExecutor>]
public static void Cleanup()
{
_documentFile.Close(false);
}
[Test]
[NotInParallel]
[TestExecutor<RevitThreadExecutor>]
public async Task FilteredElementCollector_ElementTypes_ValidAssignable()
{
var elements = new FilteredElementCollector(_documentFile)
.WhereElementIsElementType()
.ToElements();
using (Assert.Multiple())
{
await Assert.That(elements).IsNotEmpty();
await Assert.That(elements).All().Satisfy(element => element.IsAssignableTo<ElementType>());
}
}
[Test]
[NotInParallel]
[TestExecutor<RevitThreadExecutor>]
public async Task Delete_Dimensions_ElementsWithDependenciesDeleted()
{
var elementIds = new FilteredElementCollector(_documentFile)
.WhereElementIsNotElementType()
.OfCategory(BuiltInCategory.OST_Dimensions)
.OfClass(typeof(RadialDimension))
.ToElementIds();
using var transaction = new Transaction(_documentFile);
transaction.Start("Delete dimensions");
var deletedElements = _documentFile.Delete(elementIds);
transaction.Commit();
await Assert.That(deletedElements.Count).IsGreaterThanOrEqualTo(elementIds.Count);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
-
net8.0-windows7.0
- Nice3point.Revit.Api.RevitAPI (>= 2026.2.0)
- TUnit (>= 0.25.21)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.