A base class for xUnit tests that need to unit-test compile-time helper classes or query the Metalama code model.
Implements
Namespace: Metalama.Testing.UnitTesting
Assembly: Metalama.Testing.UnitTesting.dll
Syntax
public abstract class UnitTestClass : IDisposableRemarks
This class provides the infrastructure for writing unit tests of compile-time logic used by aspects, without executing the aspects themselves. Test methods should call CreateTestContext(string?, string?) to obtain a TestContext that provides access to Metalama services.
A typical test workflow is:
- Create a test context using CreateTestContext(string?, string?)
- Create a compilation using CreateCompilation(string, string?, bool, IEnumerable<MetadataReference>?, string?, bool)
- Optionally switch execution context using WithExecutionContext(ICompilation, string?) if your code uses ExpressionFactory
- Query the code model or call your compile-time helper classes
- Assert expected results
The test context must be disposed at the end of each test method.
Constructors
| Name | Description |
|---|---|
| UnitTestClass(ITestOutputHelper?, bool) |
Properties
| Name | Description |
|---|---|
| TestOutput | Gets an object allowing to write to the test output. |