Package: Invex.Atom.TestUtils
Atom provides test utilities for verifying your build definitions, targets, and modules in unit/integration tests.
dotnet add package Invex.Atom.TestUtilsInvex.Atom.TestUtils provides helpers for:
- Creating test build definitions
- Mocking services (file system, process runner, etc.)
- Verifying target execution order
- Testing parameter resolution
- Validating generated workflow models
CreateTestHost<T> creates an Atom host with test providers and an in-memory file system. This
example verifies that a target was discovered:
using Invex.Atom.Build.Definition;
using Invex.Atom.Build.Hosting;
using Invex.Atom.Build.Model;
using Invex.Atom.TestUtils;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;
[BuildDefinition]
internal sealed partial class TestBuild : BuildDefinition
{
public Target SayHello => t => t
.Executes(() => Logger.LogInformation("Hello, World!"));
}
public sealed class BuildTests
{
[Test]
public void Build_discovers_target()
{
using var host = TestUtils.CreateTestHost<TestBuild>();
var model = host.Services.GetRequiredService<BuildModel>();
model.Targets.ShouldContainKey(nameof(TestBuild.SayHello));
}
}For target execution tests, retrieve the registered BuildExecutor, provide the desired
CommandLineArgs, and assert on the resulting target state or captured TestConsole output.
Verify that your workflow definitions produce the expected YAML by:
- Instantiating the build definition in a test context.
- Running the workflow resolver.
- Comparing the output model against expected values.
- Use
System.IO.Abstractions.TestingHelpers(already a dependency) for in-memory file system testing. - Mock
IProcessRunnerto avoid executing real processes in tests. - Use snapshot testing to verify generated YAML doesn't change unexpectedly.