Skip to content

ricaun-io/RevitTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RevitTest.Samples

Revit 2019 Visual Studio 2022 Nuke License MIT Build nuget

RevitTest.Samples

ricaun.RevitTest is a multi-version NUnit testing framework for Revit API. Support Revit 2019 to 2025.

This project contain samples and the basic info about the ricaun.RevitTest Framework.

Features

  • Run tests and debug using Visual Studio to execute tests inside Revit.

  • Open and Close Revit and dotnet test execution.

Discussions

RevitTest Discussions is a place to share ideas and aks questions about the framework.

Samples

The sample project contains the basic usage of the ricaun.RevitTest Framework.

Install

To install the ricaun.RevitTest.TestAdapter, you can use the NuGet package manager.

PackageReference

The main package is ricaun.RevitTest.TestAdapter that manage the NUnit test execution of tests inside Revit.

The machine need to have the Autodesk Revit installed to work.

<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="ricaun.RevitTest.TestAdapter" Version="*" />

.Net Core

If you are using .Net Core, you need to add the Microsoft.NET.Test.Sdk package to the .csproj file.

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="*" Condition="!$(TargetFramework.StartsWith('net4'))" />

IsTestProject

If your are using dotnet test to execute the tests, you need to add the IsTestProject property to the .csproj file.

<IsTestProject>true</IsTestProject>

Example

The framework injects the UIApplication, UIControllerApplication, Application, and ControllerApplication Revit objects to the tests methods, use in the method with [OneTimeSetUp] or [SetUp].

using Autodesk.Revit.UI;
using NUnit.Framework;

public class RevitTest
{
    private UIApplication uiapp;
    [OneTimeSetUp]
    public void Setup(UIApplication uiapp)
    {
        this.uiapp = uiapp;
    }
    [Test]
    public void VersionName()
    {
        Assert.IsNotNull(uiapp);
        System.Console.WriteLine(uiapp.Application.VersionName);
    }
}

ricaun.RevitTest

The ricaun.RevitTest Framework is composed by 3 projects:

---
title: ricaun.RevitTest
---
flowchart LR
    dll(dll)
    TestAdapter[TestAdapter]
    Console[Console]
    Application[Application]
    dll--dotnet test-->TestAdapter
    TestAdapter--Start-->Console
    Console--Run Tests-->Application
    Console-.Open/Close.-Revit
    subgraph Revit [Revit]
        Application
    end
Loading
  • TestAdapter: The NUnit TestAdapter is responsible for executing the Console and waits for the tests results.
  • Console: The Console application responsible for communicating with Revit, installing the Application, and opening/closing Revit.
  • Application: The Revit Plugin application is responsible for executing the tests sent by Console.

FAQ

The ricaun.RevitTest Framework is free to use ?

Yes.

What are the requirements to use ricaun.RevitTest Framework ?

It is a requirement to have Autodesk Revit installed on the machine to run the tests in the official software.

The ricaun.RevitTest Framework is open-source ?

Not available yet.

Do you need an account to use the ricaun.RevitTest Framework ?

Yes, an Autodesk account is required inside Revit.

The ricaun.RevitTest Framework collects any use data ?

No.

The ricaun.RevitTest Framework works offline ?

Yes.

The ricaun.RevitTest Framework works with Design Automation for Revit ?

Yes, is possible to switch the Console to run the tests using the Design Automation for Revit instead of the Revit for desktop. (Not available yet)

The ricaun.RevitTest Framework works in Rider ?

Yes, the TestAdapter could work with Rider after some configuration, check the discussion: #8

Do you have plans to create a similar test framework for AutoCAD or Inventor ?

Could be possible, but I only use Revit so I don't have the incentive to do that.

How the ricaun.RevitTest Framework knows what Revit version to open ?

The TestAdapter checks for some RevitApi reference in the test assembly and get the version from it. If not found, the TestAdapter will use the lowest version of Revit installed in the machine.

How the force to use a specific Revit version ?

To overwrite the version selection of the TestAdapter, you can use the AssemblyMetadataAttribute property with NUnit.Version in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Version", "2024")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Version</_Parameter1>
    <_Parameter2>2024</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How the force to use a specific Revit language ?

To force the TestAdapter to open Revit with a specific language, you can use the AssemblyMetadataAttribute property with NUnit.Language in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Language", "ENU")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Language</_Parameter1>
    <_Parameter2>ENU</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How the force to open a new Revit process ?

By default TestAdapter uses the Revit process opened with the same version to run the tests. To overwrite and force to open a new process, you can use the AssemblyMetadataAttribute property with NUnit.Open in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Open", "true")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Open</_Parameter1>
    <_Parameter2>true</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How the force to close Revit after the test finish ?

By default TestAdapter does not closes Revit after finish a test. To overwrite and force to close Revit, you can use the AssemblyMetadataAttribute property with NUnit.Close in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Close", "true")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Close</_Parameter1>
    <_Parameter2>true</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How to enable log in the TestAdapter ?

The log verbosity has two levels 1(Normal) and 2(Debug), to enable you can use the AssemblyMetadataAttribute property with NUnit.Verbosity in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Verbosity", "1")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Verbosity</_Parameter1>
    <_Parameter2>1</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How change the timeout for the TestAdapter ?

By default TestAdapter have a timeout of 10 minutes. To set the timeout you can use the AssemblyMetadataAttribute property with NUnit.Timeout in the test project, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Timeout", "10")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Timeout</_Parameter1>
    <_Parameter2>10</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
How the force Revit to open with Viewer Mode ?

To force the TestAdapter to open Revit open with Viewer Mode, you can use the AssemblyMetadataAttribute property with NUnit.Language in the test project to inject the /viewer command, like this:

In the .cs file:

[assembly: System.Reflection.AssemblyMetadata("NUnit.Language", "ENU /viewer")]

Or in the .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
    <_Parameter1>NUnit.Language</_Parameter1>
    <_Parameter2>ENU /viewer</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>

The dialog box will be closed automatically when Revit is opened using the Viewer Mode when using TestAdapter.

Revit 2025 - viewer mode dialog Viewer mode allows all functionality of Revit, except the following: save or save as in all cases; exporting or publishing modified projects; exporting or publishing any projects to a format containing model data that can be modified; or printing projects after changes are made.

License

This project is licensed under the MIT License.


Do you like this project? Please star this project on GitHub!