How thomhurst/tunit works
Main Components
• Core Runtime and Test Infrastructure – Represented by projects such as TUnit.Core and TUnit.Engine. These contain the logic for test discovery, registration, execution, orchestration of hooks (before/after, assembly, class, test), and management of test contexts/events.
• Assertion Library – Shown as TUnit.Assertions (and its variants) which provides an asynchronous, fluent API for making assertions throughout tests.
• Analyzers and Code Fix Providers – The file tree shows a range of analyzer projects (TUnit.Analyzers.*, TUnit.Assertions.Analyzers.CodeFixers, etc.) that enforce best practices and help the developer catch errors during compile time.
• Source Generation Infrastructure – A key architectural piece that “finds” tests at compile time without using reflection, registering them to be executed by the engine. This component is implicit in the design and helps power the “source generated tests” model.
• Templates and Scaffolding – TUnit.Templates along with the Example and Playground projects, which help users to install and bootstrap their test projects.
• Integration with External Test Platforms – Components like TUnit.Playwright indicate that there is support for UI/Browser testing; and the documentation points to integrations with Visual Studio, Rider, VS Code, and the CLI.
• Build and Pipeline Support – TUnit.Pipeline and the existence of GitHub CI/CD files, actions, and release configurations indicate a decoupled pipeline that builds, packages, performs analysis and runs tests.
• Additional Supporting Tools – There are several “tools” directories (e.g. for speed comparisons, nuget tester, and benchmark projects) that enrich the development and performance testing of the framework.
Out Relationships and Data Flow
• The Core Testing Engine (TUnit.Core and TUnit.Engine) is the heart and orchestrates test discovery via source generators. It interacts with the Assertion Library to validate test results.
• The analyzers (from TUnit.Analyzers and TUnit.Assertions.Analyzers) act as “companion” tools – they hook into the build process to provide diagnostics. They analyze code structure before runtime.
• The Templates provide a starting point for consumers, and depend on the Core, Assertions, and Engine packages.
• External test runners (via IDE adapters, CLI commands, and the Microsoft.Testing.Platform integration) pass commands to the Engine, which then uses events and hooks to manage test lifecycles.
• The Pipeline modules are responsible for continuous integration tasks (packaging, version generation, running tests, etc.) and interface with the code repositories and deployment systems.
Architectural Patterns and Principles
• Layered Architecture – Each set of assemblies (Core, Engine, Assertions, Analyzers) are separated by responsibilities.
• Dependency Injection and Hook/Event Patterns – Test and lifecycle hooks clearly indicate use of dependency injection patterns, property injection, and event subscription to manage resource lifecycles.
• Extensibility – The use of source generators and customizable data sources (attributes like [MatrixDataSource], [ClassDataSource<T>], etc.) means the system is built to be extended by users.
• Build/Pipeline Separation – The build scripts and CI/CD pipeline modules are separated as independent modules under TUnit.Pipeline.