Testing Contracts & Mutation Testing
Under Principle 12 (Tests are executable contracts), tests in EricksonLopez.* serve as living behavioral specifications that appear directly in CI telemetry and Stryker.NET mutation testing reports.
Every unit, integration, concurrency, and security test method follows:
[UnitOfWork]_[ScenarioUnderTest]_[ExpectedBehavior]Test projects intentionally suppress CA1707 and IDE1006 so semantic underscores remain clean under <TreatWarningsAsErrors>true</TreatWarningsAsErrors>:
<PropertyGroup Condition="$(MSBuildProjectDirectory.Contains('tests'))"> <NoWarn>$(NoWarn);CA1707;IDE1006</NoWarn></PropertyGroup>Executable Contract Example (EricksonLopez.Result.Testing)
Section titled “Executable Contract Example (EricksonLopez.Result.Testing)”using EricksonLopez.Result;using EricksonLopez.Result.Testing;using Xunit;
namespace Example.Domain.UnitTests;
public sealed class OrderValidationTests{ [Fact] public void Create_WhenTotalIsNonPositive_ReturnsValidationFailure() { // Arrange decimal invalidTotal = 0m;
// Act Result result = invalidTotal <= 0m ? Result.Failure(Error.Validation("Order.InvalidTotal", "Total must exceed zero.")) : Result.Success();
// Assert result.ShouldBeFailure(); result.ShouldHaveErrorCode("Order.InvalidTotal"); result.ShouldHaveErrorType(ErrorType.Validation); }}- 1:1 Project Symmetry: Every
src/assembly pairs with a dedicated unit test suite. - Concurrency & Race Validation: CAS, idempotency claims, key ring cache invalidation, and distributed locks include concurrent stress tests.
- Security Threat Suites:
dotnet-securityanddotnet-xmlenforce adversarial tests for timing attacks, memory zeroing, SSRF, and XXE prevention. - Mutation Testing (
Stryker.NET): Verifies that assertions kill logical, arithmetic, and boundary mutants rather than merely inflating line coverage.