← All writing
/writing

Split Your Test Projects So a Wrong Dependency Won't Compile

A single Tests project referencing everything is convenient, and it quietly destroys one of the best guarantees you have.

The problem

If your test project references both the Application layer and Entity Framework, then an accidental using Microsoft.EntityFrameworkCore; inside a use case still compiles. Your dependency rule is now documentation.

The arrangement

Give each layer its own test project, referencing only what that layer is allowed to see:

MyApp.Application.Tests     -> references Application only
MyApp.Infrastructure.Tests  -> references Infrastructure

Now an EF Core type leaking into a use case fails to build in Application.Tests, at the exact moment it's introduced, with an error that names the file.

Why it matters

This is the cheapest architectural test you will ever write, because you don't write it. There's no reflection-based convention test to maintain, no NetArchTest assertions drifting out of date. The project reference graph is the assertion.

The temptation to merge them is real — two projects means two dotnet test invocations and some duplicated fixtures. Resist it. The duplication is a few builder helpers. What you'd be trading away is the only thing stopping your layers collapsing into each other over a couple of busy quarters.

If the shared fixtures genuinely hurt, extract a small TestSupport project that references nothing but the domain.

← All writing