ArchUnit-Unity
ArchUnit-Unity wraps ArchUnitNET for Unity’s test framework, so layering rules, dependency constraints and naming conventions can be written as regular EditMode tests. A rule like “the Domain NameSpace should not depend on Infrastructure” stops being a comment in a wiki or ADR and becomes an assertion that runs with the rest of your suite and fails the build the moment it’s violated.
This matters more now that a growing share of the code in a repository is written by an AI agent rather than a person who sat in on the architecture discussion. An agent will happily wire up a dependency cycle or reach straight into a layer it was never supposed to touch, because nothing stops it from doing so. Architecture tests do: the rule is enforced in the test suite regardless of who, or what, wrote the code that broke it.
Supports both Mono and CoreCLR 🙂
With ArchUnit-Unity you can finally tame his noodliness.
Rationale
I first read about ArchUnit in early 2023, in “Building Evolutionary Architectures”, by Rebecca Parsons, Neal Ford and Patrick Kua. The authors introduce the concept of architecture fitness functions which are objective tests that verify an architecture’s characteristics hold over time.
Keeping the static structure of a codebase sound is one such fitness function, and ArchUnit is the tool they point to for testing it. ArchUnit started in the Java world and has since been ported to other ecosystems, including .NET, the way good tools tend to spread.
There was no equivalent for Unity3D: no public package, no blog post, no sign that anyone in our industry was using this approach. ArchUnit-Unity is my attempt to change that. It also fits where I position myself professionally, bringing deep Unity3D knowledge into an enterprise and business oriented world, combining that engine level knowledge with the thinking, patterns and strategy of enterprise software.
DevLog
Getting this off the ground turned out to be more straightforward than expected, since ArchUnitNET already ships a Mono.Cecil-based build that runs fine under Unity’s current Mono/IL2CPP scripting backend. I pulled in that existing port (ArchUnitNET.dll, plus its StronglyConnectedComponents and System.Collections.Immutable dependencies) as precompiled plugins rather than building from source, and set up the package around it: a Runtime-less package split into Editor and Tests Editor assembly definitions, each wired with the right references so the plugins only get pulled into the Editor assembly where ArchUnitNET is actually used.
With the assemblies in place I wrote a small smoke test suite to confirm the wrapper and the underlying library actually hold up inside the Unity test runner, and added the two Unity-specific helpers the README shows: ArchUnitAssert.Check() to run a rule and surface ArchUnitNET’s violation report as a standard NUnit failure, and ArchUnitPackages / AsmdefAssemblyLoader to resolve a package’s Runtime, Editor and Tests assemblies by Unity’s folder convention instead of hand-rolling reflection against asmdef files.
CI came last: a GitHub Actions workflow runs EditMode tests against Unity 2021.3.0f1 LTS through game-ci/unity-test-runner, a separate commitlint workflow enforces conventional commits, and a release workflow that only runs once the tests pass hands versioning and the changelog to semantic-release.
The open item is the Mono dependency itself. Unity 6.7 drops the Mono scripting backend in favor of CoreCLR, and the bundled ArchUnitNET build won’t load there. The plan is to support both backends side by side and load the right ArchUnitNET build based on compiler flags, switching between a Mono-targeted and a CoreCLR-targeted dependency depending on which scripting backend the project is running.
I also added CoreCLR support recently which indeed proved to be fairly straightforward for such a thin wrapper over ArchUnitNet.