Repository navigation
Add --zero-tests-policy option, default to allow-skipped for skipped tests - #9415
Conversation
…tests Introduce a new --zero-tests-policy CLI option (allow-skipped|strict) that controls whether an all-skipped run is treated as zero tests (exit code 8). The default is 'allow-skipped': skipped tests count as run, so only a run that discovered no test at all returns exit code 8. Use 'strict' for the previous behavior where an all-skipped run fails with exit code 8. The policy is honored consistently across the three mirrored sites: process exit code (TestApplicationResult), the in-process terminal/console verdict (TestRunSummaryHelper / TerminalTestReporter), and the MSBuild run summary (plumbed cross-process via RunSummaryInfoRequest). Fixes #9385 Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR updates Microsoft.Testing.Platform (and MSTest acceptance coverage) to introduce a new --zero-tests-policy <allow-skipped|strict> option that separates “zero tests discovered” from “all tests skipped”, and flips the default behavior so all-skipped runs succeed by default.
Changes:
- Added
--zero-tests-policy(defaultallow-skipped) and plumbed the effective policy through exit code calculation, terminal verdict rendering, and MSBuild summary reporting. - Updated unit + acceptance tests and
--help/--infoexpectations to validate the new policy and the default behavior change. - Added localized resource strings and updated platform changelog entry.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/TestApplicationResultTests.cs | Updates/extends exit-code unit tests to cover default vs strict/allow-skipped policy behavior. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/TestRunSummaryHelperTests.cs | Adds verdict/failure tests for default vs strict/allow-skipped policy behavior. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs | Adds validation tests for accepted/invalid --zero-tests-policy values. |
| test/IntegrationTests/MSTest.Acceptance.IntegrationTests/InconclusiveTests.cs | Updates acceptance expectations for skipped-only runs to succeed under the new default policy. |
| test/IntegrationTests/MSTest.Acceptance.IntegrationTests/IgnoreTests.cs | Splits coverage into strict-policy vs default-policy tests for all-ignored scenarios. |
| test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs | Updates MSTest help text expectations to include --zero-tests-policy. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxSkippedTestTests.cs | Pins TRX-skipped expectations to --zero-tests-policy strict to preserve TRX assertions. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs | Updates platform help/info expectations to include --zero-tests-policy. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoAllExtensionsTests.cs | Updates “all extensions” help/info expectations to include --zero-tests-policy. |
| test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceAssert.cs | Extends summary assertion helper to optionally treat all-skipped as “Zero tests ran” (strict-only). |
| src/Platform/Microsoft.Testing.Platform/Services/TestApplicationResult.cs | Implements policy-aware “zero tests” exit code gating using skipped vs executed counts. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf | Adds localized entries for --zero-tests-policy description and invalid-argument message. |
| src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx | Adds resource strings for the new CLI option description and validation error. |
| src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.cs | Exposes the new invalid-argument resource accessor for non-core builds/unit tests. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/TestRunSummaryHelper.cs | Makes verdict/failure logic policy-aware (default pass for all-skipped, strict fails). |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.Initialization.cs | Passes resolved ZeroTestsPolicy into terminal reporter options. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporterOptions.cs | Adds ZeroTestsPolicy to terminal reporter options. |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.Summary.cs | Uses policy-aware verdict/failure computation to color/render summary consistently. |
| src/Platform/Microsoft.Testing.Platform/CommandLine/ZeroTestsPolicy.cs | Introduces internal enum representing the policy modes. |
| src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs | Registers option, validates values, and exposes GetZeroTestsPolicy(...). |
| src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs | Makes MSBuild summary verdict match effective policy (via request flag). |
| src/Platform/Microsoft.Testing.Extensions.MSBuild/Serializers/RunSummaryRequestSerializer.cs | Extends run-summary pipe payload with AllowSkipped so MSBuild side can mirror behavior. |
| src/Platform/Microsoft.Testing.Extensions.MSBuild/MSBuildConsumer.cs | Sends AllowSkipped flag derived from command line to MSBuild task via named pipe. |
| docs/Changelog-Platform.md | Documents the new option and default behavior change in the platform changelog. |
Copilot's findings
- Files reviewed: 36/36 changed files
- Comments generated: 4
- Add ZeroTestsPolicy.cs to TerminalReporterContract.props so the standalone contract project compiles its own copy instead of resolving the internal MTP type (CS0122 on Windows). - Use 'using' declarations for TestApplicationResult instances in the new tests. - Point the changelog entry at PR #9415 instead of the issue. Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ode cref - PlatformCommandLineProvider: use a list pattern ([string ...]) when validating the --zero-tests-policy argument so the validator can never index an empty array (defensive; arity validation already short-circuits the CLI path first). - ZeroTestsPolicy: fully-qualify the <see cref> to Microsoft.Testing.Platform.Helpers.ExitCode.ZeroTests for stable doc resolution. Co-authored-by: Copilot <[email protected]>
🧪 Test quality grade — PR #941522 tests graded across 8 files (10 unit, 12 integration). 21 earn A — excellent naming, focused assertion coverage, and clean AAA structure throughout. One pre-existing structural issue in a modified test pulls its grade down. Key recommendation:
This advisory comment was generated automatically. Grades are heuristic
|
Fixes #9385.
Summary
Exit code
8(ZeroTests) was overloaded: it fired for both zero tests discovered (a bad filter / empty assembly — the "pointless run" we wanted to catch) and all tests skipped (often legitimate:[Ignore], conditional/platform skips). This PR introduces a new outcome-based CLI option to separate the two, and flips the default so all-skipped runs are treated as successful.New option:
--zero-tests-policy <allow-skipped|strict>allow-skipped(default)strictallow-skipped(default): skipped tests count as "run", so only a run where no test was discovered at all returns exit code 8. An all-skipped run now succeeds.strict: the original behavior from If all tests are skipped, exit code is 0 not 8 #3216 / Skipped tests count as not run #3243 — skipped tests don't count, so an all-skipped (or zero-test) run fails with exit code 8.--ignore-exit-code 8remains an orthogonal blunt override.--minimum-expected-tests(exit 9) stays independent and unaffected.Implementation
The policy is resolved once and honored consistently across the three mirrored sites that were previously kept "in lockstep":
TestApplicationResulttracks the skipped count and gatesExitCode.ZeroTestson the policy.TestRunSummaryHelper(IsRunFailed/GetVerdictText) and the terminal/simplified-console reporters render "Passed!" instead of red "Zero tests ran" for an all-skipped run underallow-skipped.AllowSkippedfield onRunSummaryInfoRequest(named-pipe protocol, both ends ship from this repo), so the MSBuildPassed!/Failed!summary line matches.TRX outcome already derives from the exit code, so it flips to
Completedautomatically.Tests & docs
TestApplicationResultTests), verdict logic (TestRunSummaryHelperTests), and option validation (PlatformCommandLineProviderTests) for both policies.IgnoreTests(default vsstrict),InconclusiveTests, andTrxSkippedTestTests(pinned tostrictto preserve TRX-content assertions). SharedAssertOutputContainsSummaryhelper updated with anallSkippedIsZeroTestsopt-in.--help/--infoexpectations across the MTP and MSTest acceptance files..xlf; changelog entry.Co-authored-by: Copilot [email protected]