Purview.SourceGeneratorFramework.Testing.TUnit
1.0.0-prerelease.27
See the version list below for details.
dotnet add package Purview.SourceGeneratorFramework.Testing.TUnit --version 1.0.0-prerelease.27
NuGet\Install-Package Purview.SourceGeneratorFramework.Testing.TUnit -Version 1.0.0-prerelease.27
<PackageReference Include="Purview.SourceGeneratorFramework.Testing.TUnit" Version="1.0.0-prerelease.27" />
<PackageVersion Include="Purview.SourceGeneratorFramework.Testing.TUnit" Version="1.0.0-prerelease.27" />
<PackageReference Include="Purview.SourceGeneratorFramework.Testing.TUnit" />
paket add Purview.SourceGeneratorFramework.Testing.TUnit --version 1.0.0-prerelease.27
#r "nuget: Purview.SourceGeneratorFramework.Testing.TUnit, 1.0.0-prerelease.27"
#:package Purview.SourceGeneratorFramework.Testing.TUnit@1.0.0-prerelease.27
#addin nuget:?package=Purview.SourceGeneratorFramework.Testing.TUnit&version=1.0.0-prerelease.27&prerelease
#tool nuget:?package=Purview.SourceGeneratorFramework.Testing.TUnit&version=1.0.0-prerelease.27&prerelease
Purview.SourceGeneratorFramework.Testing.TUnit
TUnit integration for testing incremental C# source generators built with Purview.SourceGeneratorFramework.
Installation
dotnet add package Purview.SourceGeneratorFramework.Testing.TUnit
What's included
TUnitSourceGeneratorTestBase<TGenerator>— ready-made base class for TUnit tests. It wires generator log output toTestContext.Current.OutputWriter.- Custom TUnit assertions for inspecting
DriverRunResultinstances directly in TUnit tests. - MSBuild
.props— automatically addsglobal usingdirectives forPurview.SourceGeneratorFramework.Testing.TUnitandPurview.SourceGeneratorFramework.Testing.TUnit.Assertions.
Usage
Reference the package from a TUnit test project:
<ItemGroup>
<PackageReference Include="TUnit" />
<PackageReference Include="Purview.SourceGeneratorFramework.Testing.TUnit" />
</ItemGroup>
Derive your test class from TUnitSourceGeneratorTestBase<TGenerator> and use the inherited GenerateAsync method:
using Purview.SourceGeneratorFramework.Testing.TUnit;
public class MyGeneratorTests : TUnitSourceGeneratorTestBase<MyGenerator>
{
[Test]
public async Task GeneratesExpectedSource()
{
var source = """
[MyNamespace.MyAttribute]
public partial class MyClass { }
""";
var result = await GenerateAsync(source);
result.AssertNoCompilationErrors();
var generated = result.AssertSingleGeneratedSource();
await Assert.That(generated).Contains("public static partial class MyClass");
}
}
The base class also provides access to the underlying SourceGeneratorTestRunner<TGenerator> behavior through GenerateAsync.
Using generated types in the TUnit project
If test source files use generated attributes or other generated declarations while the tests also
derive from TUnitSourceGeneratorTestBase<TGenerator>, reference the generator project both as an
analyzer and as a normal assembly:
<ItemGroup>
<ProjectReference
Include="..\..\src\MyGenerator\MyGenerator.csproj"
PrivateAssets="all"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
<ProjectReference
Include="..\..\src\MyGenerator\MyGenerator.csproj"
PrivateAssets="all"
ReferenceOutputAssembly="true"
/>
</ItemGroup>
For example, the analyzer reference allows a test fixture to use [MyGeneratedAttribute], while
the normal reference allows the test class to derive from
TUnitSourceGeneratorTestBase<MyGenerator>. Do not add OutputItemType="Analyzer" to the normal
reference.
For multi-target TUnit projects, the normal reference means the generator's Roslyn dependencies
participate in reference resolution for every target. Build the generator against the oldest
compatible Roslyn version (Roslyn 4.13 for a .NET 8–10 test matrix) and avoid forcing a newer
System.Collections.Immutable version through central package management. The framework's
RegisterEmbeddedAttribute helper can be used instead of Roslyn 4.14's
AddEmbeddedAttributeDefinition API when .NET 8 compatibility is required.
License
This project is licensed under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.9.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.13.0)
- Purview.SourceGeneratorFramework.Testing (>= 1.0.0-prerelease.27)
- TUnit.Assertions (>= 1.65.51)
- TUnit.Core (>= 1.65.51)
-
net8.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.9.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.13.0)
- Purview.SourceGeneratorFramework.Testing (>= 1.0.0-prerelease.27)
- TUnit.Assertions (>= 1.65.51)
- TUnit.Core (>= 1.65.51)
-
net9.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.9.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.13.0)
- Purview.SourceGeneratorFramework.Testing (>= 1.0.0-prerelease.27)
- TUnit.Assertions (>= 1.65.51)
- TUnit.Core (>= 1.65.51)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-prerelease.44 | 8 | 9/18/2026 |
| 1.0.0-prerelease.43 | 26 | 9/17/2026 |
| 1.0.0-prerelease.42 | 101 | 9/14/2026 |
| 1.0.0-prerelease.41 | 49 | 9/14/2026 |
| 1.0.0-prerelease.40 | 52 | 9/13/2026 |
| 1.0.0-prerelease.39 | 60 | 9/12/2026 |
| 1.0.0-prerelease.38 | 50 | 9/12/2026 |
| 1.0.0-prerelease.37 | 83 | 9/8/2026 |
| 1.0.0-prerelease.36 | 79 | 9/6/2026 |
| 1.0.0-prerelease.35 | 73 | 9/5/2026 |
| 1.0.0-prerelease.34 | 63 | 9/5/2026 |
| 1.0.0-prerelease.33 | 73 | 9/4/2026 |
| 1.0.0-prerelease.32 | 69 | 9/3/2026 |
| 1.0.0-prerelease.31 | 69 | 9/3/2026 |
| 1.0.0-prerelease.30 | 81 | 9/3/2026 |
| 1.0.0-prerelease.29 | 74 | 9/3/2026 |
| 1.0.0-prerelease.28 | 68 | 9/2/2026 |
| 1.0.0-prerelease.27 | 76 | 9/1/2026 |
| 1.0.0-prerelease.26 | 107 | 8/29/2026 |
| 1.0.0-prerelease.25 | 83 | 8/27/2026 |