CriticalTests 3.0.0
dotnet add package CriticalTests --version 3.0.0
NuGet\Install-Package CriticalTests -Version 3.0.0
<PackageReference Include="CriticalTests" Version="3.0.0" />
<PackageVersion Include="CriticalTests" Version="3.0.0" />
<PackageReference Include="CriticalTests" />
paket add CriticalTests --version 3.0.0
#r "nuget: CriticalTests, 3.0.0"
#:package CriticalTests@3.0.0
#addin nuget:?package=CriticalTests&version=3.0.0
#tool nuget:?package=CriticalTests&version=3.0.0
<p align="center"> <img src="icon.png" width="96" alt="CriticalTests logo" /> </p>
<h1 align="center">CriticalTests</h1>
<p align="center"> Enforce test contracts for critical classes in .NET. <br/> Mark a class as critical — the pipeline fails if it lacks tests or coverage. </p>
<p align="center"> <img alt="NuGet" src="https://img.shields.io/nuget/v/CriticalTests?style=flat-square" /> <img alt=".NET" src="https://img.shields.io/badge/.NET-netstandard2.0%2B-512BD4?style=flat-square" /> <img alt="License" src="https://img.shields.io/badge/license-MIT-green?style=flat-square" /> </p>
The problem
Large codebases grow without tests. You know which classes are critical — payment processing, authentication, core domain logic — but nothing enforces that they are actually tested. A developer adds a feature, skips the test, the pipeline passes, and a bug ships.
The solution
Mark critical classes with [Critical]. The package automatically fails your pipeline if:
- A critical class has no test class for a declared
TestKind - A critical class falls below its declared minimum coverage
Installation
dotnet add package CriticalTests
Quick start
1. Mark your critical classes
[Critical(TestKind.Unit, TestKind.Integration)]
public class AccountService { }
[Critical("Handles all financial transactions", minCoverage: 80, TestKind.Unit, TestKind.Integration)]
public class PaymentService { }
2. Create criticaltest.json in your test project root
{
"assemblies": [
"MyCompany.Core",
"MyCompany.Domain"
]
}
3. Add to your test .csproj
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutputFormat>json</CoverletOutputFormat>
<CoverletOutput>./bin/Debug/net5.0/coverage.json</CoverletOutput>
</PropertyGroup>
<ItemGroup>
<Content Include="criticaltest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
4. Write test classes following the naming convention
public class AccountServiceUnitTests { ... }
public class AccountServiceIntegrationTests { ... }
5. Run the pipeline in two stages
# Stage 1 — run tests and generate coverage report
dotnet test --filter "FullyQualifiedName!~CriticalContractTests"
# Stage 2 — validate contracts against the coverage report
dotnet test --filter "FullyQualifiedName~CriticalContractTests" --no-build
[Critical] attribute
| Parameter | Type | Default | Description |
|---|---|---|---|
Required |
TestKind[] |
— | Test types that must exist |
MinCoverage |
int |
100 |
Minimum line coverage percentage (0–100) |
Reason |
string |
"" |
Documents why the class is critical |
public enum TestKind { Unit, Integration, Load }
Naming convention
The validator expects test class names to contain both the production class name and the TestKind:
| Production class | Required test classes |
|---|---|
AccountService + [Unit, Integration] |
AccountServiceUnitTests, AccountServiceIntegrationTests |
TokenValidator + [Unit] |
TokenValidatorUnitTests |
Pipeline output on violation
TEST CONTRACT VIOLATED
MyCompany.Core.Services.AccountService => missing test class of type [Integration]
INSUFFICIENT COVERAGE IN CRITICAL CLASSES
x MyCompany.Core.Services.PaymentService: current = 75% | required = 80%
GitHub Actions example
- name: Run tests and collect coverage
run: dotnet test --filter "FullyQualifiedName!~CriticalContractTests"
- name: Validate critical contracts
run: dotnet test --filter "FullyQualifiedName~CriticalContractTests" --no-build
Documentation
- Package Overview — architecture, components and pipeline flow
- Usage Guide — step-by-step setup and examples
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.4)
- System.Text.Json (>= 10.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release: CriticalAttribute, RegistryScanner and contract validation.