Tutorial

2.6 Guard the project's shape

Some rules are about the whole project rather than one test: every train has an interface to be called and recorded by, and tests do not sleep, skip or assert the old way. Trax ships those checks as test fixtures. A project subclasses them and writes no test bodies.

tests/Shopfront.Tests/ArchitectureGuards.cs:

using System.Reflection;
using Shopfront.Trains.PlaceOrder;
using Trax.Core.Testing.Fixtures;
using Trax.Mediator.Testing;
 
namespace Shopfront.Tests;
 
[TestFixture]
public sealed class ShopfrontTrainGuards : TrainGuardFixture
{
    protected override IReadOnlyList<Assembly> TrainAssemblies =>
        [typeof(IPlaceOrderTrain).Assembly];
}
 
[TestFixture]
public sealed class ShopfrontHygieneGuards : HygieneGuardFixture;

TrainGuardFixture fails when a train has no companion interface. HygieneGuardFixture reads the source under tests/, relative to the folder holding the solution, and fails on an [Ignore], a fixed Task.Delay or Thread.Sleep, and NUnit's Assert.That. That last one is why these tests assert with AwesomeAssertions: its failures say what was expected and why, in the words of the because argument.

SDK Reference

ITrainBus | UseInMemory | SaveTrainParameters | Metadata | Mediator testing | Architecture guards


Next: 2.7 Run them