|
| 1 | +--- |
| 2 | +name: revit-nunit |
| 3 | +description: > |
| 4 | + Configure and run in-host NUnit tests with the RevitDevTool.NUnit NuGet |
| 5 | + package (Microsoft Testing Platform). Use in any repo that references that |
| 6 | + package when writing or running NUnit tests inside Revit, AutoCAD, or |
| 7 | + Civil 3D; setting HostName/HostVersion/HostLaunch; using `dotnet test --filter`; |
| 8 | + selecting [Explicit] tests; or diagnosing MTP exit code 8 / zero tests. |
| 9 | +--- |
| 10 | + |
| 11 | +# Host NUnit tests (RevitDevTool.NUnit) |
| 12 | + |
| 13 | +Standalone consumer skill. Copy this folder into any repo (or |
| 14 | +`~/.agents/skills/revit-nunit/`). |
| 15 | + |
| 16 | +``` |
| 17 | +dotnet test (MTP exe) → installed DevTools.NUnit.Runner → host pipe → NUnit 4.6.1 |
| 18 | +``` |
| 19 | + |
| 20 | +The MTP exe never runs test bodies locally. Requires |
| 21 | +[RevitDevTool](https://github.com/trgiangv/RevitDevTool) installed and NuGet |
| 22 | +`RevitDevTool.NUnit`. |
| 23 | + |
| 24 | +Detect: `PackageReference` `RevitDevTool.NUnit` + `global.json` in **that |
| 25 | +project folder** (not the repo root) with |
| 26 | +`"test": { "runner": "Microsoft.Testing.Platform" }`. |
| 27 | + |
| 28 | +## Configure |
| 29 | + |
| 30 | +Pin **NUnit 4.6.1**. Do not add `NUnit.Microsoft.Testing.Platform`, |
| 31 | +`NUnit3TestAdapter`, or `ricaun.RevitTest.TestAdapter`. |
| 32 | + |
| 33 | +```xml |
| 34 | +<PropertyGroup> |
| 35 | + <IsTestProject>true</IsTestProject> |
| 36 | + <OutputType>Exe</OutputType> |
| 37 | + <RuntimeIdentifiers>win-x64</RuntimeIdentifiers> |
| 38 | + <HostName>Revit</HostName> |
| 39 | + <HostVersion>2024</HostVersion> |
| 40 | + <HostLaunch>false</HostLaunch> |
| 41 | + <HostTimeout>60</HostTimeout> |
| 42 | + <HostLaunchTimeout>360</HostLaunchTimeout> |
| 43 | +</PropertyGroup> |
| 44 | +<ItemGroup> |
| 45 | + <PackageReference Include="RevitDevTool.NUnit" /> |
| 46 | + <PackageReference Include="Microsoft.Testing.Platform.MSBuild" /> |
| 47 | + <PackageReference Include="NUnit" Version="4.6.1" /> |
| 48 | +</ItemGroup> |
| 49 | +``` |
| 50 | + |
| 51 | +Create `global.json` **in the test project folder** (same directory as the |
| 52 | +`.csproj`). Do **not** put it at the repo root — that forces every test |
| 53 | +project in the tree onto MTP. |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "sdk": { "version": "10.0.0", "rollForward": "latestMinor" }, |
| 58 | + "test": { "runner": "Microsoft.Testing.Platform" } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +Property meanings, RID/`OutputType`, and conflicting packages: |
| 63 | +[project-setup.md](references/project-setup.md). |
| 64 | + |
| 65 | +## Run |
| 66 | + |
| 67 | +Always `cd` to the **test project folder** (where `global.json` and the |
| 68 | +`.csproj` live) before `dotnet test`. Do not run from the repo root. |
| 69 | + |
| 70 | +```powershell |
| 71 | +cd path/to/Host.Tests |
| 72 | +dotnet test --project Host.Tests.csproj -c <Config> --filter MethodName |
| 73 | +dotnet test --project Host.Tests.csproj -c <Config> -- --filter MethodName |
| 74 | +dotnet test --project Host.Tests.csproj -c <Config> --list-tests |
| 75 | +``` |
| 76 | + |
| 77 | +`--filter` is the **NUnit method name only**. Same command runs `[Explicit]`. |
| 78 | +Do not start `Revit.exe` / `acad.exe` yourself. |
| 79 | + |
| 80 | +Filter / exit 8: [mtp-filter.md](references/mtp-filter.md). |
| 81 | + |
| 82 | +## Write tests |
| 83 | + |
| 84 | +Bodies run on the Autodesk API context. Use the host context type for |
| 85 | +`Application`, `TestContext.WorkDirectory` for assets. Patterns: |
| 86 | +[test-patterns.md](references/test-patterns.md). |
| 87 | + |
| 88 | +## Common mistakes |
| 89 | + |
| 90 | +| Mistake | Fix | |
| 91 | +|---------|-----| |
| 92 | +| `--filter "Name=…"` / `FullyQualifiedName~` | `--filter MethodName` | |
| 93 | +| `[Explicit]` never runs | Select it with `--filter MethodName` | |
| 94 | +| No exe / test project does not run | Set `OutputType=Exe` and `RuntimeIdentifiers=win-x64` in the csproj | |
| 95 | +| Ran from repo root / another project | `cd` to the test project folder that has `global.json` | |
| 96 | +| Timeout | Raise `HostTimeout` (60s is smoke-only) | |
| 97 | + |
| 98 | +## Package |
| 99 | + |
| 100 | +- NuGet: [RevitDevTool.NUnit](https://www.nuget.org/packages/RevitDevTool.NUnit) |
| 101 | +- Installer / Runner: [RevitDevTool](https://github.com/trgiangv/RevitDevTool) |
| 102 | + |
| 103 | +## References |
| 104 | + |
| 105 | +- [project-setup.md](references/project-setup.md) |
| 106 | +- [mtp-filter.md](references/mtp-filter.md) |
| 107 | +- [test-patterns.md](references/test-patterns.md) |
0 commit comments