Skip to content

Add --zero-tests-policy option, default to allow-skipped for skipped tests - #9415

Merged
Amaury Levé (Evangelink) merged 4 commits into
mainfrom
evangelink-relax-exit-code-8-skipped-tests
Jun 25, 2026
Merged

Amaury Levé (Evangelink) merged 4 commits into
mainfrom
evangelink-relax-exit-code-8-skipped-tests

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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>

Value Zero discovered All skipped
allow-skipped (default) exit 8 exit 0
strict exit 8 exit 8 (previous behavior)
  • allow-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 8 remains an orthogonal blunt override. --minimum-expected-tests (exit 9) stays independent and unaffected.

⚠️ Behavior change: the default flips so an all-skipped run no longer fails. Users who relied on the old behavior can opt back in with --zero-tests-policy strict.

Implementation

The policy is resolved once and honored consistently across the three mirrored sites that were previously kept "in lockstep":

  • Process exit code — TestApplicationResult tracks the skipped count and gates ExitCode.ZeroTests on the policy.
  • In-process verdict — TestRunSummaryHelper (IsRunFailed / GetVerdictText) and the terminal/simplified-console reporters render "Passed!" instead of red "Zero tests ran" for an all-skipped run under allow-skipped.
  • MSBuild summary — the effective policy is plumbed cross-process via a new AllowSkipped field on RunSummaryInfoRequest (named-pipe protocol, both ends ship from this repo), so the MSBuild Passed!/Failed! summary line matches.

TRX outcome already derives from the exit code, so it flips to Completed automatically.

Tests & docs

  • Unit tests: exit-code (TestApplicationResultTests), verdict logic (TestRunSummaryHelperTests), and option validation (PlatformCommandLineProviderTests) for both policies.
  • Acceptance: IgnoreTests (default vs strict), InconclusiveTests, and TrxSkippedTestTests (pinned to strict to preserve TRX-content assertions). Shared AssertOutputContainsSummary helper updated with an allSkippedIsZeroTests opt-in.
  • Updated --help / --info expectations across the MTP and MSTest acceptance files.
  • Resource strings + regenerated all .xlf; changelog entry.

Co-authored-by: Copilot [email protected]

…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]>
Copilot AI review requested due to automatic review settings June 25, 2026 05:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default allow-skipped) and plumbed the effective policy through exit code calculation, terminal verdict rendering, and MSBuild summary reporting.
  • Updated unit + acceptance tests and --help/--info expectations 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

Comment thread docs/Changelog-Platform.md Resolved
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review June 25, 2026 07:06
- 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]>
@Evangelink

This comment has been minimized.

@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 25, 2026
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) June 25, 2026 07:26
Copilot AI review requested due to automatic review settings June 25, 2026 07:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 37/37 changed files
  • Comments generated: 3

@Evangelink

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]>
@Evangelink

Copy link
Copy Markdown
Member Author

🧪 Test quality grade — PR #9415

22 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: InconclusiveTests.TestOutcomeShouldBeRespectedCorrectly uses multiple if/else blocks to route assertions based on the lifecycle parameter. While this pattern is common in parameterized integration tests, separating the "failed path" and "skipped/success path" into two distinct data-driven tests would improve diagnostic clarity when a case regresses.

ΔTestGradeBandNotes
mod InconclusiveTests.
TestOutcomeShouldBeRespectedCorrectly
D 60–69 Pre-existing if/else blocks drive assertions per lifecycle step; split into per-outcome tests for clarity.
mod HelpInfoAllExtensionsTests.
Help_
WithAllExtensionsRegistered_
OutputFullHelpContent
A 90–100 No issues found.
mod HelpInfoTests.
Help_
WhenMSTestExtensionRegistered_
OutputHelpContentOfRegisteredExtension
A 90–100 No issues found.
mod HelpInfoTests.
Help_
WhenNoExtensionRegistered_
OutputDefaultHelpContent
A 90–100 No issues found.
new IgnoreTests.
WhenAllTestsAreIgnored_
ByDefault_
ExitsSuccessfully
A 90–100 No issues found.
mod IgnoreTests.
WhenAllTestsAreIgnored_
WithStrictPolicy_
AssemblyInitializeAndCleanupAreSkipped
A 90–100 No issues found.
new PlatformCommandLineProviderTests.
IsInvalid_
If_
ZeroTestsPolicy_
Has_
IncorrectValue
A 90–100 No issues found.
new PlatformCommandLineProviderTests.
IsValid_
If_
ZeroTestsPolicy_
Has_
CorrectValue
A 90–100 No issues found.
mod TestApplicationResultTests.
GetProcessExitCodeAsync_
If_
All_
Skipped_
ByDefault_
Returns_
Success
A 90–100 No issues found.
new TestApplicationResultTests.
GetProcessExitCodeAsync_
If_
All_
Skipped_
With_
AllowSkippedPolicy_
Returns_
Success
A 90–100 No issues found.
new TestApplicationResultTests.
GetProcessExitCodeAsync_
If_
All_
Skipped_
With_
StrictPolicy_
Returns_
ZeroTestsRan
A 90–100 No issues found.
new TestApplicationResultTests.
GetProcessExitCodeAsync_
If_
No_
Tests_
With_
AllowSkippedPolicy_
Returns_
ZeroTestsRan
A 90–100 No issues found.
new TestRunSummaryHelperTests.
GetVerdictText_
WhenAllTestsSkipped_
ByDefault_
ReturnsPassed
A 90–100 No issues found.
new TestRunSummaryHelperTests.
GetVerdictText_
WhenAllTestsSkipped_
WithAllowSkippedPolicy_
ReturnsPassed
A 90–100 No issues found.
mod TestRunSummaryHelperTests.
GetVerdictText_
WhenAllTestsSkipped_
WithStrictPolicy_
ReturnsZeroTestsRan
A 90–100 No issues found.
new TestRunSummaryHelperTests.
GetVerdictText_
WhenZeroTests_
WithAllowSkippedPolicy_
ReturnsZeroTestsRan
A 90–100 No issues found.
new TestRunSummaryHelperTests.
IsRunFailed_
WhenAllTestsSkipped_
ByDefault_
ReturnsFalse
A 90–100 No issues found.
new TestRunSummaryHelperTests.
IsRunFailed_
WhenAllTestsSkipped_
WithAllowSkippedPolicy_
ReturnsFalse
A 90–100 No issues found.
mod TestRunSummaryHelperTests.
IsRunFailed_
WhenAllTestsSkipped_
WithStrictPolicy_
ReturnsTrue
A 90–100 No issues found.
new TestRunSummaryHelperTests.
IsRunFailed_
WhenZeroTests_
WithAllowSkippedPolicy_
ReturnsTrue
A 90–100 No issues found.
mod TrxSkippedTestTests.
Trx_
UsingDataDriven_
CreatesUnitTestTagForEachOneInsideTheTrx
A 90–100 No issues found.
mod TrxSkippedTestTests.
Trx_
WhenSkipTest_
ItAppearsAsExpectedInsideTheTrx
A 90–100 No issues found.

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Grade Tests on PR (on open / sync) workflow. · 971.6 AIC · ⌖ 13.9 AIC · ⊞ 43.7K · [◷]( · ◷)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relax exit code 8 (zero tests) for skipped tests

3 participants