Add acceptance tests for duplicate TestMethod and TestClass attributes#7224
Merged
Youssef1313 merged 8 commits intodev/ygerges/single-attributefrom Jan 14, 2026
Merged
Add acceptance tests for duplicate TestMethod and TestClass attributes#7224Youssef1313 merged 8 commits intodev/ygerges/single-attributefrom
Youssef1313 merged 8 commits intodev/ygerges/single-attributefrom
Conversation
- 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>
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 (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
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
Youssef1313
reviewed
Jan 14, 2026
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CustomAttributesTests.cs
Show resolved
Hide resolved
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>
Evangelink
reviewed
Jan 14, 2026
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CustomAttributesTests.cs
Show resolved
Hide resolved
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CustomAttributesTests.cs
Outdated
Show resolved
Hide resolved
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CustomAttributesTests.cs
Show resolved
Hide resolved
Youssef1313
reviewed
Jan 14, 2026
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CustomAttributesTests.cs
Outdated
Show resolved
Hide resolved
- 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>
Youssef1313
reviewed
Jan 14, 2026
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task CustomTestClassAttribute_ShouldDiscoverAndRun(string tfm) |
Member
There was a problem hiding this comment.
- 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."
Contributor
Author
There was a problem hiding this comment.
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>
Youssef1313
reviewed
Jan 14, 2026
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task CustomTestMethodAttribute_ShouldDiscoverAndRun(string tfm) |
Member
There was a problem hiding this comment.
- 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.
Contributor
Author
There was a problem hiding this comment.
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:
DuplicateTestMethodAttributefor testing duplicate TestMethod attributesDuplicateTestClassAttributefor 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
e9a3c71
into
dev/ygerges/single-attribute
2 of 7 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds MSTest acceptance tests validating that duplicate attributes derived from
TestMethodAttributeandTestClassAttributeare properly detected and reported as failures.Test Coverage
The tests validate two distinct failure scenarios:
[TestMethod]and custom[MyTestMethod]attributes on the same method, which causes one test to fail while other tests in the class pass[TestClass]and custom[MyTestClass]attributes that should fail with proper error messageTest Structure
Two separate test methods with dedicated test assets provide focused validation:
DuplicateTestMethodAttribute_ShouldFail: Uses theDuplicateTestMethodAttributetest asset and validates that the exit code isAtLeastOneTestFailedwith 1 test passing and 1 test failingDuplicateTestClassAttribute_ShouldFail: Uses theDuplicateTestClassAttributetest 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
DuplicateTestClassAttribute Test Asset
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.