-
Notifications
You must be signed in to change notification settings - Fork 288
Apply TestCategory from derived class on inherited test methods #513
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
Merged
jayaranigarg
merged 15 commits into
microsoft:master
from
spanglerco:category-from-derived-class
Apr 9, 2019
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cf164f8
Apply TestCategory from derived class on inherited test methods
spanglerco d028c40
Merge branch 'master' into category-from-derived-class
spanglerco 90892d4
Merge branch 'master' into category-from-derived-class
spanglerco 160eb6f
Preserve DeclaringClassFullName from discovery to execution
spanglerco d587fa8
Restore GetCustomAttributeForAssembly taking in a MemberInfo, but ref…
spanglerco f3f9267
Merge branch 'master' into category-from-derived-class
singhsarab 92459ad
Merge branch 'master' into category-from-derived-class
jayaranigarg e56e4d0
Merge branch 'master' into category-from-derived-class
spanglerco 67658d1
Filter out duplicate test methods
spanglerco f77b7c9
Merge branch 'master' into category-from-derived-class
jayaranigarg a09b144
Fix compile after latest merge from master
spanglerco 7f0f8d5
Merge branch 'master' into category-from-derived-class
spanglerco 16854dc
Merge branch 'master' into category-from-derived-class
jayaranigarg 0cca8df
Merge branch 'master' into category-from-derived-class
jayaranigarg 30ef7fa
Merge branch 'master' into category-from-derived-class
jayaranigarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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.
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.
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.memberinfo.declaringtype?view=netframework-4.7.2#System_Reflection_MemberInfo_DeclaringType
It seems the situation you were facing was only because the test method wasn't overridden. From the 4 scenarios in the link, one of the scenarios is this issues particular scenario. Just to be sure can you provide the behavior for the rest of the three scenarios.
I know this seems far fetched, but this could lead to a big breaking change so I just want to make sure :)
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.
Good idea. I took the example class hierarchy from that link and added test attributes to get this: https://gist.github.com/spanglerco/fdb04b4a6bab1be2963f6063c937a587
It actually exposes an interesting corner case for classes that hide test methods (not that I can immediately think of a use case for that). Here's the result of using vstest.console to run the tests filtered by one category at a time with 1.4.0:
The interesting thing is that test category A gets applied to B's
new Test(), but instead of running bothA.Test()with an instance of B andB.Test(), it runsB.Test()twice. But test category B only applies toB.Test(), so it runs once for that category. Test category C isn't applied toA.Test(), which is my original scenario.Here's the results with this change:
A and D remain the same, but now that the test category of the subclass is applied to inherited methods, test category C includes
A.Test()on an instance of C. A side-effect is that test category B then includes a second run ofB.Test()like what happens in test category A.The reason the duplicate execution happens is because the discoverer only sends the
TestMethod.FullClassNameand not theTestMethod.DeclaringClassFullName, so when the executor reacquires the MethodInfo, it does so on B instead of A, making it ambiguous. It simply chooses the first result, which is theB.Test()one. Assuming that it's considered backwards compatible to add new property values to theTestCase, it seems this could be fixed by sending the declaring class name as an optional property value and the executor can use that to find the correct MethodInfo.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.
@spanglerco, this is really good stuff. The changes look good but can we come up with a solution to avoid running tests multiple times for overloaded methods?
Since this is a case for overloading, for test category B the expectation would be that
B.Testis run only once and sinceA.Testis being overloaded it should not run when running tests for categoryB.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.
@karanjitsingh I should have read this part more clearly to start with. I have a working implementation that resolves the duplicate execution, but I would have thought the desired behavior would be that test category B would run both
B.TestandA.Teston an instance of B since B has both of those methods defined at the same time (B.Testis hidingA.Test, butA.Testis still there):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.
@spanglerco, in the case of this type of overload, the language specifies
A.Testwill be run if the object is of type A or the reference for object B is of type A, there is no right way here in this case but I would want to follow the convention that the language follows.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.
@spanglerco, any update on this?
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.
@karanjitsingh, sorry for the delay, I haven't had a lot of time to look into this lately. I was able to tweak TypeEnumerator to remove the duplicate methods with these results: