Skip to content

Add CIConditionAttribute to support CI-specific test execution control - #5797

Merged
Amaury Levé (Evangelink) merged 13 commits into
mainfrom
copilot/fix-5533
Jul 15, 2025
Merged

Amaury Levé (Evangelink) merged 13 commits into
mainfrom
copilot/fix-5533

Conversation

Copilot AI commented Jun 17, 2025 •

Copy link
Copy Markdown
Contributor

This PR implements CIConditionAttribute to allow developers to conditionally run or skip tests based on whether they are executing in a Continuous Integration (CI) environment.

Summary

The new attribute addresses a common need in test suites where certain tests should behave differently in CI environments - either running only in CI or being temporarily disabled in CI (e.g., for flaky tests).

Usage

[TestMethod]
[CICondition(ConditionMode.Include)]  // Run only in CI
public void PerformanceTestOnlyInCI()
{
    // Resource-intensive test that should only run in CI infrastructure
}

[TestMethod]
[CICondition(ConditionMode.Exclude)]  // Skip in CI
public void FlakyTestTemporarilyDisabledInCI()
{
    // Temporarily disable flaky test in CI while keeping it for local development
}

Implementation Details

  • Follows existing patterns: Inherits from ConditionBaseAttribute like OSConditionAttribute

  • Comprehensive CI detection: Supports major CI systems including:

    • GitHub Actions (GITHUB_ACTIONS)
    • Azure Pipelines (TF_BUILD)
    • AppVeyor (APPVEYOR)
    • Travis CI (TRAVIS)
    • CircleCI (CIRCLECI)
    • Jenkins (BUILD_ID + BUILD_URL)
    • TeamCity (TEAMCITY_VERSION)
    • AWS CodeBuild (CODEBUILD_BUILD_ID + AWS_REGION)
    • Google Cloud Build (BUILD_ID + PROJECT_ID)
    • JetBrains Space (JB_SPACE_API_URL)
    • Generic CI (CI)
  • CI detection logic: Based on the well-documented detection from .NET SDK telemetry (https://learn.microsoft.com/dotnet/core/tools/telemetry#continuous-integration-detection)

  • Comprehensive testing: 20+ unit tests covering all CI detection scenarios and edge cases

  • API consistency: Updated PublicAPI files for proper API tracking

Use Cases

  1. Flaky test management: Temporarily disable problematic tests in CI while keeping them active for local development
  2. Resource-intensive tests: Run performance or integration tests only in CI environments with adequate resources
  3. CI-specific scenarios: Handle tests that depend on CI infrastructure or specific CI configurations

The attribute can be applied to both test methods and test classes, supporting standard MSTest condition attribute grouping behavior.

Fixes #5533.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add CIConditionAttribute Add CIConditionAttribute to support CI-specific test execution control Jun 17, 2025

Copilot AI commented Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)
    • Triggering command: dotnet build test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj --verbosity quiet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI commented Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI commented Jun 20, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25316.2.txt (dns block)
    • Triggering command: ./.dotnet/dotnet test test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj --filter ShouldRun_ExcludeMode_WhenNotInCI_ReturnsTrue --verbosity normal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review July 15, 2025 07:37
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) July 15, 2025 07:37
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/fix-5533 branch July 15, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CIConditionAttribute

3 participants