![]() |
VOOZH | about |
Dropping support for Revit 2021
Requires NuGet 2.14 or higher.
dotnet add package xUnitRevitUtils.2021 --version 1.0.7
NuGet\Install-Package xUnitRevitUtils.2021 -Version 1.0.7
<PackageReference Include="xUnitRevitUtils.2021" Version="1.0.7" />
<PackageVersion Include="xUnitRevitUtils.2021" Version="1.0.7" />Directory.Packages.props
<PackageReference Include="xUnitRevitUtils.2021" />Project file
paket add xUnitRevitUtils.2021 --version 1.0.7
#r "nuget: xUnitRevitUtils.2021, 1.0.7"
#:package xUnitRevitUtils.2021@1.0.7
#addin nuget:?package=xUnitRevitUtils.2021&version=1.0.7Install as a Cake Addin
#tool nuget:?package=xUnitRevitUtils.2021&version=1.0.7Install as a Cake Tool
👁 Twitter Follow
👁 Community forum users
👁 website
👁 docs
An xUnit runner for Autodesk Revit.
Check out our blog post on this 👉 https://speckle.systems/blog/xunitrevit !
xUnitRevit uses speckle.xunit.runner.wpf which is a fork of xunit.runner.wpf, it allows to easily develop and run xUnit tests in Revit.
Many thanks to all the developers of xunit and xunit.runner.wpf!
This repo is composed of 2 projects:
There are very few steps required to create and run your fist unit tests with xUnitRevit:
config.jsonAfter cloning this repo, all you need to do to run xUnitRevitRunner is to build the project corresponding to your revit version in Debug mode
This will build the project and copy its dlls to the Revit addin folder %appdata%\Autodesk\Revit\Addins.
You can also, similarly, build the project in Release mode, and manually copy the built files from xunit-Revit\Release.
Creating a test library is pretty straightforward, at least we tried to make it as simple as possible!
Just follow the steps below for Revit 2021:
xunitxUnitRevitUtils.2021That's it, now we can start adding our tests.
To do almost anything with the Revit API you need a reference to the active Document, and this is where xUnitRevitUtils comes into play, with its xru static class. The code below shows how we can use it to get a list of Walls and check their properties.
Full code : https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/SampleTest.cs
[Fact]
public void WallsHaveVolume()
{
var testModel = GetTestModel("walls.rvt");
var doc = xru.OpenDoc(testModel);
var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
foreach(var wall in walls)
{
var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED);
Assert.NotNull(volumeParam);
Assert.True(volumeParam.AsDouble() > 0);
}
doc.Close(false);
}
To be able to share context between tests, xUnits uses fixtures. We can use fixtures for instance, to open a Revit model only once and use it across multiple tests.
Let's see an example, full code: https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/TestWithFixture.cs
public class DocFixture : IDisposable
{
public Document Doc { get; set; }
public IList<Element> Walls { get; set; }
public DocFixture()
{
var testModel = Utils.GetTestModel("walls.rvt");
Doc = xru.OpenDoc(testModel);
Walls = new FilteredElementCollector(Doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
}
public void Dispose()
{
}
}
public class TestWithFixture : IClassFixture<DocFixture>
{
DocFixture fixture;
public TestWithFixture(DocFixture fixture)
{
this.fixture = fixture;
}
[Fact]
public void CountWalls()
{
Assert.Equal(4, fixture.Walls.Count);
}
[Fact]
public void WallOffset()
{
var wall = fixture.Doc.GetElement(new ElementId(346573));
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
Assert.Equal(2000, baseOffset);
}
}
Another feature of xUnitRevitUtils is that it offers a helper method to run Transactions, so you don't have to worry about that 🤯! Check the example below: https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/TestWithFixture.cs
[Fact]
public void MoveWallsUp()
{
var walls = fixture.Walls.Where(x => x.Id.IntegerValue != 346573);
xru.RunInTransaction(() =>
{
foreach(var wall in walls)
{
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
var baseOffset = UnitUtils.ConvertToInternalUnits(2000, param.DisplayUnitType);
param.Set(baseOffset);
}
}, fixture.Doc)
.Wait(); // Important! Wait for action to finish
foreach (var wall in walls)
{
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
Assert.Equal(2000, baseOffset);
}
}
We've added a couple of optional settings for lazy developers like me, to help speed up frequent testing of a test library. You'll see a config_sample.json in the root of the project. Copy the file and rename the copy to config.json and set it to copy local = true. You'll then be able to configure
startupAssemblies: if set, automatically loads a set of assemblies when xUnitRevit startsautoStart: if true, automatically opens the xUnitRevit window after Revit loadsDlls loaded by xUnitRevit are loaded in Revit's AppDomain, and therefore it's not possible to recompile them until Revit is closed (even if you see an auto reload option in the UI). But don't despair, since Revit 2020 it's possible to edit & continue your code while debugging, so you won't have to restart Revit each time.
As for next steps, we're planning to add additional features to run xUnitRevit from a CI/CD routine.
Stay tuned!
xUnitRevit was developed to help us develop a better Speckle 2.0 connector for Revit, we hope you'll find it useful too.
Want to suggest a feature, report a bug, submit a PR? Please open an issue to discuss first!
Please make sure you read the and for an overview of the practices we try to follow.
The Speckle Community hangs out on the forum, do join and introduce yourself & feel free to ask us questions!
For any security vulnerabilities or concerns, please contact us directly at security[at]speckle.systems.
Unless otherwise described, the code in this repository is licensed under the MIT License. Please note that some modules, extensions or code herein might be otherwise licensed. This is indicated either in the root of the containing folder under a different license file, or in the respective file's header. If you have any questions, don't hesitate to get in touch with us via .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
Showing the top 1 popular GitHub repositories that depend on xUnitRevitUtils.2021:
| Repository | Stars |
|---|---|
|
specklesystems/speckle-sharp
.NET SDK, Schema and Connectors: Revit, Rhino, Grasshopper, Dynamo, ETABS, AutoCAD, Civil3D & more.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.0.7 | 8,325 | 6/7/2023 | 1.0.7 is deprecated because it is no longer maintained. |
| 1.0.6 | 1,248 | 3/9/2023 | 1.0.6 is deprecated because it is no longer maintained. |
| 1.0.4 | 9,232 | 10/31/2020 | 1.0.4 is deprecated because it is no longer maintained. |
| 1.0.3 | 876 | 9/15/2020 | 1.0.3 is deprecated because it is no longer maintained. |
| 1.0.1 | 1,066 | 7/30/2020 | 1.0.1 is deprecated because it is no longer maintained. |
| 1.0.0 | 1,211 | 7/1/2020 | 1.0.0 is deprecated because it is no longer maintained. |
| 0.0.3 | 623 | 3/9/2023 | 0.0.3 is deprecated because it is no longer maintained. |