-
Notifications
You must be signed in to change notification settings - Fork 105
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
Resolve issue with custom tests names and test Ids #668
Conversation
… and set a unique Id based on the NUnit ID value.
Note: I believe this change may fix other open issues. I will associate them to this PR as I verify them. |
Note: I see the CI failures and will investigate them as soon as I can. |
This "Issue" (placeholder) is related to this PR: #505 |
@johnmwright This looks like a huge improvement. I love that all my tests now show under a single grouping as that's how I expected them to show in the first place. Great work, and a wonderful explanation in the PR! It looks like some test cases may need to be updated though to match the changes:
|
Yeah, there's a few test failures that I missed in my local runs. I'll need some time to address them. |
src/NUnit.TestAdapter.Tests.Acceptance/TestSourceWithCustomNames.cs
Outdated
Show resolved
Hide resolved
…tyle assert for typeof
… fullname instead of the possibly-customized test case's fullname.
I've updated the logic (and my description in "How I addressed the issue:") to be more accurate and handle more cases that were failing to parse the passed-in filters from VS (such as |
@johnjaylward Thanks for this! It's been fixed in my latest push.
|
.history | ||
/Dump |
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.
Ignoring the "dump" files created when troubleshooting builds using the DumpXml
utility.
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.
It looks like this will be a big improvement. 👍
The key highlights being:
- The FQN is based on Type+Method and independent of DisplayName.
- The TestCaseId is unique across all test cases (including data-driven ones) and deterministic between discovery sessions.
@peterwald thanks! I realized I forgot to put a TL;DR at the top of the PR description, so I borrowed your "key highlights" for that purpose :) |
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.
The cake script should have been updated to 3.16.0, but can do that in the next step, so that we get a pre-release in the 3.16 series
@johnmwright Thank you for this awesome work! I believe this PR is the best one we have ever received. It is straight to the point, and the documentation you have added is way above anything else I have seen! Not only is the documentation comprehensive and well structured, the code simple and readable, tests have been added, but you have also taken the time to verify the resolution to a bunch of other similar issues! Really appreciate this work! |
Happy to help! |
This PR is to address #622
Key highlights:
Background information:
TestCase.FullyQualifiedName
to be the actual test method name (not the display name), optionally including param types (not values). Basically, the details that would have been returned fromcaller.GetType().FullName
TestCase.Id
, the class with create a GUID value based on theTestCase.FullyQualifiedName
.FullyQualifiiedName
, which the NUnitAdapter attempt to apply inTfsTestFilter.CheckFilter(TestCase)
.FullyQualifiedName
to determine the namespace groupingsTestCase.Id
is equal), then it will show the test once in the UI, with multiple result values, such as this (which is how MSTest-based tests display results when a method is used for test cases):How this issue manifested:
DisplayName
andFullyQualifiedName
to the display name of the test, which break the contract with VS if the user has utilized theSetName()
method to override the display name value. While VS doesn't strictly enforce theFullyQualifiedName
is an actual method, it does have some minor validation to make sure some special characters are used as expected, such as paired parenthesis, resulting in an error such as:How I addressed the issue:
TestCase.FullyQualfiedName
to the actual test method name, this conforms with the expectations from VS and fixes the parsing issues. Since the NUnit-parsed data includes aclassname
andmethodname
attribute, the FQN can be created from that (or, at least, a close-enough version).FullyQualifiedName
, if the adapter doesn't explicitly set theTestCast.Id
, it will result in each TestCase having the default Id based on the FQN, as described in the Background Information above. Meaning: When the adapter recreates the TestCase object for association with the TestResult object returned with the test results, it would return several results with the same TestCase.Id value, since each of those would have the same FQN. This resulted in the UI displaying the results under the same Test (similar to the screenshot above). This does not match the existing behavior, where each test case is listed as it's own node in the test case explorer. Additionally, only the first DisplayName was shown in the UI, since it ignored tests with identical Ids, due to Ids needing to be unique. Since NUnit already applies a unique id to each test, which is consistent across test runs, I decided to resolve this issue by assigning theTestCase.Id
property using the NUnit id attribute value. This will give each TestCase a unique Id even if they have the sameFullyQualifiedName
, resulting in the individual nodes that is currently used.Impacts of changes
I primarily used two sets of tests while working on this PR. The first is a test class I put together from the use cases listed in #622, which I put into this gist and ultimately added as a unit test in this PR. The other is the sample solution provided in comments to #622 . I'll be using these to describe the impacts of this change.
Before the changes, when the problematic parameterized tests were run, you would see:
Repo_jwright.DemoTest2
in screenshot 1), in addition to the parameterized custom names (ex:Repo_jwright.Name with mismatched quote '"c'
) as peers.Repo_jwright.DemoTest2
in screenshot 1)ExpressionTransatorTest
in screenshot 2)Screenshot 1:
Screenshot 2:
After the changes:
Repo_jwright.DemoTest2
in screenshot 1)Screenshot 1:
Possible Breaking Change
Because this PR changes how the
TestCase.Id
property is generated, this will result in test cases having different IDs than they did before the change was implemented. Any systems that expect the test ID value to remain the same across history will lose their tracking of test cases.This is specifically called out in the inline comments of
EqtHash.GuidFromString
in the VSTest codebase, but with the references between TFS/MsftDevOps Bugs and TFS/MsftDevOps workitems. I am unsure what, if any, associations TFS/MsftDevOps places with test run results.