Alchemist
Generate a dedicated UnitTests project with placeholder unit tests for a C# solution with one command.
Alchemist is for .NET developers who want a fast and consistent starting point for test coverage without handwriting each test class, method and attribute from scratch.
Install
Install as a global .NET tool.
dotnet tool install --global KuBuCo.Alchemist
The published tool now targets .NET 8 to reduce install friction on real user machines. The solution you run it against can still target newer SDKs, but that solution must have the SDKs it needs on the machine where generation runs.
Install into a local tool manifest.
dotnet new tool-manifest
dotnet tool install KuBuCo.Alchemist
Then run it with
alchemist --help
Use alchemist-demo to familiarise yourself with Alchemist.
Quick Start
Run Alchemist against a C# solution.
alchemist --solution ./mysolution.sln
Pick a different test framework when needed.
alchemist --solution ./mysolution.sln --framework nunit
Choose how reruns should behave.
alchemist --solution ./mysolution.sln --regeneration.mode update
Example
Source Code
namespace example;
public sealed class Calculator
{
public int Add(int left, int right)
{
return left + right;
}
}
Command:
alchemist --solution ./example.sln
Result
- Generates
UnitTests/UnitTests.csproj. - Adds the selected test framework together with shared test dependencies.
- Generates a placeholder unit test file for
Calculator.
Example Output
using Xunit;
namespace UnitTests.Example;
public class CalculatorUnitTests
{
// [UnitTestID=6A1B2C3D4E5F6789]
[Fact(Skip = "Unit test not implemented.")]
public void Add_UnitTestPlaceholder()
{
Assert.True(false, "Scaffolded Unit Test");
}
}
Supported Scenarios
Alchemist Supports
- C# Solutions
- Source projects that share one target framework.
xUnit,nUnit, andmsTest.- The generation of placeholder unit tests for public methods.
- Execution from the solution or from elsewhere when
--solutionpoints at the target.sln.
What it Generates
- A sibling
UnitTests/UnitTests.csproj. - Project references back to the source projects it examined.
- Framework-specific test packages together with shared dependencies, such as
Microsoft.NET.Test.SdkandMoq. *UnitTests.csfiles in a parallelUnitTests/tree.- Unit test methods named
<SourceMethodName>_UnitTestPlaceholder. UnitTestIDcomments to make regeneration safer.
Regeneration Behavior
Skip: Retains existing files and adds missing members.Update: Replaces matching methods and appends members.Replace: Overwrites the target file.--regeneration.labels false: DisablesUnitTestIDcomments although labels are recommended when intending to rerun.
Limitations
- Alchemist generates starting points not finished unit tests.
- The default output is scaffolded and labelled as not implemented.
- It targets public methods not each source shape in a codebase.
- It expects supported projects and one shared target framework across source projects.
- In
Updatemode, matched methods are replaced as full methods so manual edits inside them can be overwritten.