Nice3point.TUnit.Revit 2027.0.0

Prefix Reserved
dotnet add package Nice3point.TUnit.Revit --version 2027.0.0
                    
NuGet\Install-Package Nice3point.TUnit.Revit -Version 2027.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nice3point.TUnit.Revit" Version="2027.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nice3point.TUnit.Revit" Version="2027.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Nice3point.TUnit.Revit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nice3point.TUnit.Revit --version 2027.0.0
                    
#r "nuget: Nice3point.TUnit.Revit, 2027.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nice3point.TUnit.Revit@2027.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nice3point.TUnit.Revit&version=2027.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Nice3point.TUnit.Revit&version=2027.0.0
                    
Install as a Cake Tool

Testing Framework for Revit

Nuget Downloads Last Commit

Write unit tests for your Revit add-ins using the TUnit testing framework with source-generated tests, parallel execution, and Microsoft.Testing.Platform support.

Installation

You can install this library 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).*"/>

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"

You must have a licensed copy of Autodesk Revit installed on your machine to run tests, with a version that matches the selected Solution configuration.

JetBrains Rider

The Enable Testing Platform support option must be selected in Settings > Build, Execution, Deployment > Unit Testing > Testing Platform.

alternate text is missing from this package README image

Application testing

Test Revit application-level functionality using the Application property exposed by RevitApiTest:

public sealed class ApplicationTests : RevitApiTest
{
    [Test]
    [TestExecutor<RevitThreadExecutor>]
    public async Task Cities_BuiltinSet_IsNotEmpty()
    {
        var cities = Application.Cities.Cast<City>();

        await Assert.That(cities).IsNotEmpty();
    }

    [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

Tests that pass alone but fail together are a classic sign of shared state. Give each test its own document — created in [Before(Test)], closed in [After(Test)] — and that problem disappears entirely. Use the setup hook to seed the document with exactly the state each test needs. The [HookExecutor<RevitThreadExecutor>] attribute ensures hooks also run on Revit's thread:

public sealed class ModelSeedTests : RevitApiTest
{
    private Document _document = null!;
    private IList<Wall> _exteriorWalls = null!;

    [Before(Test)]
    [HookExecutor<RevitThreadExecutor>]
    public void SeedModel()
    {
        _document = Application.NewProjectDocument(UnitSystem.Metric);

        using var transaction = new Transaction(_document, "Seed model");
        transaction.Start();

        _exteriorWalls =
        [
            Wall.Create(_document, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(10, 0, 0)), level.Id, false),
            Wall.Create(_document, Line.CreateBound(new XYZ(10, 0, 0), new XYZ(10, 6, 0)), level.Id, false),
            Wall.Create(_document, Line.CreateBound(new XYZ(10, 6, 0), new XYZ(0, 6, 0)), level.Id, false),
            Wall.Create(_document, Line.CreateBound(new XYZ(0, 6, 0), new XYZ(0, 0, 0)), level.Id, false),
        ];

        transaction.Commit();
    }

    [After(Test)]
    [HookExecutor<RevitThreadExecutor>]
    public void CloseModel()
    {
        _document.Close(false);
    }

    [Test]
    [TestExecutor<RevitThreadExecutor>]
    public async Task FilteredElementCollector_ExteriorWalls_MatchSeededCount()
    {
        var walls = new FilteredElementCollector(_document)
            .WhereElementIsNotElementType()
            .OfClass(typeof(Wall))
            .ToList();

        await Assert.That(walls.Count).IsEqualTo(_exteriorWalls.Count);
    }

    [Test]
    [TestExecutor<RevitThreadExecutor>]
    public async Task Transaction_DemolishWall_RemainingWallCountDecreases()
    {
        var targetId = _exteriorWalls[0].Id;

        using var transaction = new Transaction(_document, "Demolish wall");
        transaction.Start();
        _document.Delete(targetId);
        transaction.Commit();

        var remainingWalls = new FilteredElementCollector(_document)
            .WhereElementIsNotElementType()
            .OfClass(typeof(Wall))
            .ToElementIds();

        await Assert.That(remainingWalls.Count).IsEqualTo(_exteriorWalls.Count - 1);
    }
}

The examples demonstrate basic testing functionality. This library only adds support for working within the Revit API context. For comprehensive documentation on assertions, attributes, test configuration, and advanced features, please refer to the official TUnit documentation.

More examples, including parametrized model and family tests, are available in the test project.

Test configuration

Global executor

To avoid repeating the TestExecutor attribute for every test, you can register the executor globally using one of the following methods:

  • Add the attribute to any .cs file in your project (e.g., TestsConfiguration.cs):

    using Nice3point.TUnit.Revit.Executors;
    using TUnit.Core.Executors;
    
    [assembly: TestExecutor<RevitThreadExecutor>]
    
  • Add the attribute directly to your .csproj file:

    
    <ItemGroup>
        <AssemblyAttribute Include="TUnit.Core.Executors.TestExecutorAttribute">
            <_Parameter1>typeof(Nice3point.TUnit.Revit.Executors.RevitThreadExecutor)</_Parameter1>
            <_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
        </AssemblyAttribute>
    </ItemGroup>
    

Revit Environment

TUnit initializes Revit with the English - United States language and the C:\Program Files\Autodesk\Revit {version} installation path. To override these defaults, use assembly-level attributes:

  • Add the attributes to any .cs file in your project (e.g., TestsConfiguration.cs):

    using Nice3point.Revit.Injector.Attributes;
    
    [assembly: RevitLanguage("ENU")]
    [assembly: RevitInstallationPath("D:\Autodesk\Revit Preview")]
    
  • Add the attributes directly to your .csproj file:

    
    <ItemGroup>
    
        <AssemblyAttribute Include="Nice3point.Revit.Injector.Attributes.RevitLanguageAttribute">
            <_Parameter1>ENU</_Parameter1>
        </AssemblyAttribute>
    
        <AssemblyAttribute Include="Nice3point.Revit.Injector.Attributes.RevitInstallationPathAttribute">
            <_Parameter1>D:\Autodesk\Revit $(RevitVersion)</_Parameter1>
        </AssemblyAttribute>
    
    </ItemGroup>
    

The RevitLanguage attribute accepts a language name (e.g., "English - United States"), code (e.g., "ENU") or LanguageType enum value (e.g., "English_GB" or "15").

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on Nice3point.TUnit.Revit:

Repository Stars
lookup-foundation/RevitLookup
Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
Nice3point/RevitTemplates
Templates for creating Revit add-ins
Nice3point/RevitExtensions
Extensions for Revit plugin development
Nice3point/RevitToolkit
Toolkit for Revit plugin development
mcp-servers-for-revit/mcp-servers-for-revit
🔥💧🤖 Sparx fork of the mcp-servers-for-revit/revit-mcp project
Version Downloads Last Updated
2027.0.0 172 4/7/2026
2026.1.0 267 4/7/2026
2025.1.0 236 4/7/2026
2024.1.0 131 4/7/2026
2023.1.0 261 4/7/2026
2022.1.0 97 4/7/2026
2021.1.0 98 4/7/2026
Loading failed

This release adds support for Revit 2027, testing for different languages and custom Revit installation path.

Localization support

TUnit initializes Revit with the English • United States language. To override these defaults, use assembly-level attributes:

• Add the attributes to any .cs file in your project (e.g., TestsConfiguration.cs):

   using Nice3point.Revit.Injector.Attributes;
   
   [assembly: RevitLanguage(ENU)]

• Add the attributes directly to your .csproj file:

   <!-• Revit Environment Configuration -->
   <ItemGroup>
       <AssemblyAttribute Include=Nice3point.Revit.Injector.Attributes.RevitLanguageAttribute>
           <_Parameter1>ENU</_Parameter1>
       </AssemblyAttribute>
   </ItemGroup>

The RevitLanguage attribute accepts a [language](https://help.autodesk.com/view/RVT/2026/ENU/?guid=GUID-BD09C1B4-5520-475D-BE7E-773642EEBD6C) name (e.g., English • United States), code (e.g., ENU)
or [LanguageType](https://www.revitapidocs.com/2026/dfda33cf-cbff-9fde-6672-38402e87510f.htm) enum value (e.g., English_GB or 15).

Custom Revit installation path

TUnit initializes Revit from C:\Program Files\Autodesk\Revit {version} installation path. To override these defaults, use assembly-level attributes:

• Add the attributes to any .cs file in your project (e.g., TestsConfiguration.cs):

   using Nice3point.Revit.Injector.Attributes;
   
   [assembly: RevitInstallationPath(D:\Autodesk\Revit Preview)]

• Add the attributes directly to your .csproj file:

   <!-• Revit Environment Configuration -->
   <ItemGroup>
       <AssemblyAttribute Include=Nice3point.Revit.Injector.Attributes.RevitInstallationPathAttribute>
           <_Parameter1>D:\Autodesk\Revit $(RevitVersion)</_Parameter1>
       </AssemblyAttribute>
   </ItemGroup>

Enhancements

• Added new samples
• Fixed ExecutionContext to capture AsyncLocal values like TestContext