Issue
What is the advantage to adding the @Disabled
or @Ignore
annotations to JUnit tests, e.g.:
@Test
@Disabled
void testSomething() { /* ... */ }
instead of just removing the @Test
annotation?
void testSomething() { /* ... */ }
Either way, the test should not be executed.
Solution
The utility of these annotations is largely in documentation/reporting. When you run a JUnit suite, you get a report of the results. @Ignored
/@Disabled
tests will be marked as such (with optional comments) in that report.
This lets you track how many tests are being ignored/disabled. You can set policies around this (i.e. if a test is @Ignored
for a month, just delete it) or make CI systems fail if too many tests are being @Ignored
. You can make graphs showing trends of Passed/Failed/Skipped over time.
Really, it all comes down to how you want to track the evolution of your test suite, and wether you'd want to see a section of "skipped" tests, or the total number of tests going down when a test is temporarily broken/no longer useful.
Answered By - emerssso
Answer Checked By - Katrina (JavaFixing Volunteer)