Testing Wiring
Testing Wiring
Section titled “Testing Wiring”The SDK wires the testing stack for you based on three properties that must be set before the SDK import:
| Property | Default | Description |
|---|---|---|
TestingFramework |
TUnit |
Testing framework. Supported values: TUnit, Xunit, None. |
SubstituteFramework |
TUnitMocks |
Mocking provider. Supported values: TUnitMocks, NSubstitute, None. |
TestDataFramework |
Bogus |
Test data provider. Supported values: Bogus, None. |
All three are validated at build/restore/pack time, and invalid values fail the build with a clear error.
TUnit (default)
Section titled “TUnit (default)”OutputType=Exe,TestingPlatformDotnetTestSupport=true,UseMicrosoftTestingPlatformRunner=true,EnableMicrosoftTestingPlatform=true.- The
TUnitpackage is referenced (with theMicrosoft.Testing.Platformrunner configured viaglobal.json). - A
[Category: <TestingType>]assembly attribute tags every test with its detected test category (for exampleUnit,Integration), which makes--treenode-filterfiltering work. TUnit.Mocksis referenced whenSubstituteFramework=TUnitMocks(the default).
Xunit (opt-in)
Section titled “Xunit (opt-in)”Set TestingFramework=Xunit:
xunit.v3andxunit.runner.visualstudio(private assets) are referenced.- A
[Trait("Category", "<TestingType>")]assembly attribute tags every test. OutputType=Exewhen the testing framework is notNone.
Set TestingFramework=None to disable the test runner wiring entirely. The test project is still
detected and gets coverage/IVT behaviour, but no framework packages or runner configuration are
added.
Shared test configuration
Section titled “Shared test configuration”All test and shared-testing projects get:
CollectCoverage=truewith coverage exclusions for[NSubstitute*],[TUnit.*],[xunit.*],[Microsoft.Testing.*],[Microsoft.NET.Test*], and[Bogus*].ExcludeByAttributeforExcludeFromCodeCoverageAttribute.IsPackable=false,IsPublishable=false,MaxCpuCount=0,DisableGenerateAssemblyInfoClass=true.- Disabled native instrumentation.
- An
[assembly: ExcludeFromCodeCoverage]attribute.
Substitution frameworks
Section titled “Substitution frameworks”- TUnitMocks (default) — references
TUnit.Mocks. - NSubstitute — references
NSubstituteplusNSubstitute.Analyzers.CSharp(analyzers, private assets) and a globalusing NSubstitute. - None — no mocking package.
Test data frameworks
Section titled “Test data frameworks”- Bogus (default) — references
Boguswith a globalusing Bogus. - None — no data package.
Shared testing projects
Section titled “Shared testing projects”Projects named SharedTestingFramework, SharedTestingInfrastructure, SharedTestingInfra,
SharedTestingUtilities, SharedTestingUtils, SharedTestingLibrary, SharedTestingLib, or
SharedTestingHelpers are treated as shared testing helpers:
- They get the test package references (
TUnit.Corerather than the fullTUnit) but not the test runner or coverage settings. - A
[Skip]attribute (TUnit) keeps the shared assembly from being executed directly. - Test projects automatically reference the sibling shared testing project via
../SharedTesting*/SharedTesting*.csproj.
Automatic project references
Section titled “Automatic project references”Test projects automatically reference their target project. The SDK probes
../<TargetProjectName>/, ../../<TargetProjectName>/, ../src/<TargetProjectName>/, and
../../src/<TargetProjectName>/ (whichever exists), so both the src/+tests/ and flat layouts are
covered.
Running tests
Section titled “Running tests”Tests use Microsoft.Testing.Platform (global.json sets "runner": "Microsoft.Testing.Platform")
and are filtered with TUnit tree-node filters:
dotnet test --treenode-filter "/*/*/*/*[Category=Unit]/"See Project Naming Conventions for the recognised test suffixes and InternalsVisibleTo for how test assemblies access internals.