Purview.SourceGeneratorFramework.Testing
1.0.0-prerelease.11
See the version list below for details.
dotnet add package Purview.SourceGeneratorFramework.Testing --version 1.0.0-prerelease.11
NuGet\Install-Package Purview.SourceGeneratorFramework.Testing -Version 1.0.0-prerelease.11
<PackageReference Include="Purview.SourceGeneratorFramework.Testing" Version="1.0.0-prerelease.11" />
<PackageVersion Include="Purview.SourceGeneratorFramework.Testing" Version="1.0.0-prerelease.11" />
<PackageReference Include="Purview.SourceGeneratorFramework.Testing" />
paket add Purview.SourceGeneratorFramework.Testing --version 1.0.0-prerelease.11
#r "nuget: Purview.SourceGeneratorFramework.Testing, 1.0.0-prerelease.11"
#:package Purview.SourceGeneratorFramework.Testing@1.0.0-prerelease.11
#addin nuget:?package=Purview.SourceGeneratorFramework.Testing&version=1.0.0-prerelease.11&prerelease
#tool nuget:?package=Purview.SourceGeneratorFramework.Testing&version=1.0.0-prerelease.11&prerelease
Purview.SourceGeneratorFramework.Testing
Framework-agnostic test runner and assertions for unit testing incremental C# source generators.
Installation
dotnet add package Purview.SourceGeneratorFramework.Testing
What's included
SourceGeneratorTestRunner<TGenerator>— compiles a snippet of C# source, runs the generator, and returns aDriverRunResultwith generated syntax trees, the output compilation, and captured log entries.SourceGeneratorTestBase<TGenerator>— abstract base class that accepts anITestOutputinstance for framework-specific logging integration.SourceGeneratorTestOptions— options for configuring references, namespaces, analyzer-config values, output kind, and whether to emit the output compilation to an assembly.DriverRunResult— wrapper aroundGeneratorDriverRunResultthat exposes generated trees, the output compilation, emitted assembly, and log entries.DriverRunResultExtensions— assertion helpers such asAssertNoCompilationErrors,AssertNoGenerationExceptions,AssertSingleGeneratedSource,AssertGeneratedSourceContains, and more.ITestOutput/NullTestOutput— abstraction for capturing generator log output during tests.
Usage
Reference the package from a test project and write a test using the runner directly:
<ItemGroup>
<PackageReference Include="Purview.SourceGeneratorFramework.Testing" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>
using Purview.SourceGeneratorFramework.Testing;
public class MyGeneratorTests
{
[Test]
public async Task GeneratesExpectedSource()
{
var source = """
[MyNamespace.MyAttribute]
public partial class MyClass { }
""";
var runner = new SourceGeneratorTestRunner<MyGenerator>();
var result = await runner.RunAsync(source);
result.AssertNoCompilationErrors();
var generated = result.AssertSingleGeneratedSource();
// Use your test framework's assertions, e.g. with TUnit:
// await Assert.That(generated).Contains("public static partial class MyClass");
}
}
Or derive from SourceGeneratorTestBase<TGenerator> and plug in your own ITestOutput implementation.
Options
Configure a test run with SourceGeneratorTestOptions:
var options = new SourceGeneratorTestOptions
{
IncludeDefaultNamespaces = true,
AdditionalNamespaces = ["MyNamespace"],
AdditionalAssemblyTypes = [typeof(SomeExternalType)],
CompileToAssembly = true,
AnalyzerConfigOptions = { ["build_property.MyGenerator_Disable"] = "true" }
};
var result = await runner.RunAsync(source, options);
See SourceGeneratorFramework.Testing.TUnit for a ready-made TUnit integration.
License
This project is licensed under the MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.CodeAnalysis.Analyzers (>= 5.6.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Purview.SourceGeneratorFramework (>= 1.0.0-prerelease.11)
- System.Collections.Immutable (>= 8.0.0)
-
net10.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.6.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Purview.SourceGeneratorFramework (>= 1.0.0-prerelease.11)
-
net8.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.6.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Purview.SourceGeneratorFramework (>= 1.0.0-prerelease.11)
-
net9.0
- Microsoft.CodeAnalysis.Analyzers (>= 5.6.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)
- Purview.SourceGeneratorFramework (>= 1.0.0-prerelease.11)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Purview.SourceGeneratorFramework.Testing:
| Package | Downloads |
|---|---|
|
Purview.SourceGeneratorFramework.Testing.TUnit
Purview SourceGeneratorFramework libraries for building and testing incremental C# source generators. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-prerelease.25 | 40 | 8/27/2026 |
| 1.0.0-prerelease.24 | 58 | 8/19/2026 |
| 1.0.0-prerelease.23 | 64 | 8/19/2026 |
| 1.0.0-prerelease.22 | 62 | 8/19/2026 |
| 1.0.0-prerelease.21 | 59 | 8/18/2026 |
| 1.0.0-prerelease.20 | 56 | 8/18/2026 |
| 1.0.0-prerelease.19 | 76 | 8/17/2026 |
| 1.0.0-prerelease.18 | 69 | 8/16/2026 |
| 1.0.0-prerelease.17 | 71 | 8/14/2026 |
| 1.0.0-prerelease.16 | 59 | 8/13/2026 |
| 1.0.0-prerelease.15 | 60 | 8/13/2026 |
| 1.0.0-prerelease.14 | 56 | 8/13/2026 |
| 1.0.0-prerelease.13 | 66 | 8/13/2026 |
| 1.0.0-prerelease.12 | 65 | 8/12/2026 |
| 1.0.0-prerelease.11 | 58 | 8/12/2026 |
| 1.0.0-prerelease.10 | 59 | 8/12/2026 |
| 1.0.0-prerelease.9 | 69 | 8/11/2026 |
| 1.0.0-prerelease.7 | 67 | 8/9/2026 |
| 1.0.0-prerelease.6 | 64 | 8/8/2026 |
| 1.0.0-prerelease.5 | 62 | 8/7/2026 |