Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Adds MSTest acceptance tests validating that duplicate attributes derived from TestMethodAttribute and TestClassAttribute are properly detected and reported as failures.

Test Coverage

The tests validate two distinct failure scenarios:

  1. Duplicate TestMethod attributes: Test class with both [TestMethod] and custom [MyTestMethod] attributes on the same method, which causes one test to fail while other tests in the class pass
  2. Duplicate TestClass attributes: Test class with both [TestClass] and custom [MyTestClass] attributes that should fail with proper error message

Test Structure

Two separate test methods with dedicated test assets provide focused validation:

  • DuplicateTestMethodAttribute_ShouldFail: Uses the DuplicateTestMethodAttribute test asset and validates that the exit code is AtLeastOneTestFailed with 1 test passing and 1 test failing
  • DuplicateTestClassAttribute_ShouldFail: Uses the DuplicateTestClassAttribute test asset and validates that duplicate TestClass attributes cause a failure with the expected error message "Multiple attributes of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute' found."

DuplicateTestMethodAttribute Test Asset

[TestClass]
public class TestClass1
{
    [TestMethod]
    [MyTestMethod]  // Duplicate TestMethod attribute - causes this test to fail
    public void Test1() { }

    [TestMethod]
    public void Test2() { }  // This test passes
}

public class MyTestMethodAttribute : TestMethodAttribute
{
    public MyTestMethodAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1)
        : base(callerFilePath, callerLineNumber) { }
}

DuplicateTestClassAttribute Test Asset

[TestClass]
[MyTestClass]  // Duplicate TestClass attribute - causes discovery failure
public class TestClass2
{
    [TestMethod]
    public void Test1() { }
}

public class MyTestClassAttribute : TestClassAttribute { }

The tests validate that duplicate attributes are properly detected and reported, ensuring appropriate error handling for both duplicate TestMethod and TestClass attribute scenarios.


💡 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.

- Created CustomAttributesTests.cs in MSTest.Acceptance.IntegrationTests
- Test verifies that custom attributes derived from TestMethodAttribute and TestClassAttribute work correctly
- Covers scenario with CallerFilePath and CallerLineNumber parameters
- Tests both custom TestMethod attribute on test methods and custom TestClass attribute on test classes

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 14, 2026

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 (expand for details)

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

  • rcxvsblobprodcus328.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet /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/11.0.0-beta.25617.1.txt (dns block)

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

Copilot AI changed the title [WIP] Fix TypeCache to throw on duplicate attributes when necessary Add acceptance test for custom TestMethod and TestClass attributes Jan 14, 2026
Copilot AI requested a review from Youssef1313 January 14, 2026 11:46
The TestContext property is automatically set by MSTest framework and is used to access the cancellation token in the test method.

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
- CustomTestMethodAttribute_ShouldDiscoverAndRun: filters for TestClass1 (2 tests)
- CustomTestClassAttribute_ShouldDiscoverAndRun: filters for TestClass2 (1 test)

This provides better test isolation and clearer validation of each scenario.

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>

[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task CustomTestClassAttribute_ShouldDiscoverAndRun(string tfm)
Copy link
Member

Choose a reason for hiding this comment

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

@copilot

  • Rename this test to DuplicateTestClassAttribute_ShouldFail
  • Assert exit code is not success.
  • Assert output contains "Multiple attributes of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute' found."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit 8f4cfd8:

  • Renamed test to DuplicateTestClassAttribute_ShouldFail
  • Changed assertion to AssertExitCodeIsNot(ExitCodes.Success)
  • Added assertion for error message: "Multiple attributes of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute' found."

- Renamed CustomTestClassAttribute_ShouldDiscoverAndRun to DuplicateTestClassAttribute_ShouldFail
- Changed assertion to expect non-success exit code
- Added assertion to verify error message about duplicate TestClassAttribute

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>

[TestMethod]
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
public async Task CustomTestMethodAttribute_ShouldDiscoverAndRun(string tfm)
Copy link
Member

Choose a reason for hiding this comment

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

@copilot

  • Rename this test to DuplicateTestMethodAttribute_ShouldFail
  • Assert exit code is AtLeastOneTestFailed, and assert that one test passes and one failed.

In addition, use two different test assets for the two tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit 0a42af8:

  • Renamed first test to DuplicateTestMethodAttribute_ShouldFail
  • Changed assertion to AssertExitCodeIs(ExitCodes.AtLeastOneTestFailed)
  • Added assertion for summary: 1 passed, 1 failed
  • Created two separate test assets:
    • DuplicateTestMethodAttribute for testing duplicate TestMethod attributes
    • DuplicateTestClassAttribute for testing duplicate TestClass attributes

- Renamed first test to DuplicateTestMethodAttribute_ShouldFail
- Changed assertion to AssertExitCodeIs(ExitCodes.AtLeastOneTestFailed)
- Added assertion for 1 passed, 1 failed test summary
- Split test assets into two separate projects:
  - DuplicateTestMethodAttribute: Tests duplicate TestMethod attributes
  - DuplicateTestClassAttribute: Tests duplicate TestClass attributes
- Removed filters as each test now has its own dedicated test asset

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copilot AI changed the title Add acceptance test for custom TestMethod and TestClass attributes Add acceptance tests for duplicate TestMethod and TestClass attributes Jan 14, 2026
@Youssef1313 Youssef1313 marked this pull request as ready for review January 14, 2026 14:15
@Youssef1313 Youssef1313 merged commit e9a3c71 into dev/ygerges/single-attribute Jan 14, 2026
2 of 7 checks passed
@Youssef1313 Youssef1313 deleted the copilot/sub-pr-7223 branch January 14, 2026 14:15
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.

3 participants