A tip for test cases that need to be skipped temporarily #3573
dodexahedron
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It happens.
Sometimes something breaks and you want to fix it in a dedicated branch, or there's something you're working on that you just can't figure out how to get a test case or two to pass for and want to push so someone else can look at it, or whatever. Sometimes test cases need a temporary skip.
In the past, we've done that in this project by either commenting out the InlineData or changing the data to something that will pass and dropping a comment to fix it.
Both of those have pretty big drawbacks.
But the test frameworks all have something to handle exactly that case, so that the test results can still be accurate and the broken case data can stay what it's supposed to be without the test run failing.
It's the
Skip
property of anyXunit.DataAttribute
, whichInlineData
and all the other data-providing attributes are derived from.Instead of commenting it out or changing the data to make it pass, set the Skip property in the attribute constructor to a string justifying/explaining the skip, as shown below, and the specific case will, instead, be skipped and print that string to the test output. That keeps the test result counts at the end of a run more accurate and makes it clearly visible that there's a case being skipped. They also show up in the test explorer in VS with a skip status indicator, rather than a pass, making it really easy to jump to them when working on a fix.
The Skip property comes after your data, like an initializer would, but inside the attribute constructor parentheses, rather than in curly braces, exactly as shown above.
Beta Was this translation helpful? Give feedback.
All reactions