Anarchy.Toolkit.Testing
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Testing kit · Package catalog
Shared test helpers, fixtures and assertions for toolkit-based applications.
dotnet add package Anarchy.Toolkit.Testing
- Base tests and fixtures on
TestCaseBase,TestCaseBase<TAppSettings>andEntityFixtureBase; useTestHelperfor common setup. - Test instrumentation with
TestTelemetry: anAppTelemetrywhose logs (InMemoryLoggerProvider, with properties and scopes) and metrics (InMemoryMetricRecorder) are captured in memory.services.AddTestTelemetry(capture)routes a container’s telemetry to the same capture. - API Gateway response assertions use AwesomeAssertions. Database, AWS messaging and web-specific helpers live in separate
Testing.*packages.
When to use it
Reference this package from test projects, not production services. It is useful for focused unit tests that need repeatable entities, a host environment or telemetry without sending logs and metrics to a real backend. Use the specialized test kits when the test needs a database, messaging service or web host.
How to use it
- Derive a test class from
TestCaseBaseand passFixtureTelemetry.Telemetryto the subject under test. Assert business behavior first; inspectFixtureTelemetry.LogsorFixtureTelemetry.Metricswhen telemetry itself is under test. - Derive fixtures from
EntityFixtureBase<T>and implementBuildDefaultFixture(). CallBuild()for defaults orBuild(new { Property = value })to vary only the scenario-specific fields. Null overrides requireoverrideWithNulls: true. - Use
TestCaseBase<TAppSettings>orTestHelper.TestSettings<TAppSettings>()for typed settings. Embedappsettings.jsonandappsettings.Development.jsonin the assembly declaring the settings type, and keep real credentials out of test resources.
See the testing guide for a test and fixture example.
See the testing conventions and package catalog.
Releases
See the release notes for the complete release history.