-
Notifications
You must be signed in to change notification settings - Fork 291
Add acceptance tests for duplicate TestMethod and TestClass attributes #7224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add acceptance tests for duplicate TestMethod and TestClass attributes #7224
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>
|
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:
|
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>
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
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>
|
|
||
| [TestMethod] | ||
| [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] | ||
| public async Task CustomTestClassAttribute_ShouldDiscoverAndRun(string tfm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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."
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
There was a problem hiding this comment.
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:
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>
e9a3c71
into
dev/ygerges/single-attribute
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.