Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What good are JUnit's @Ignore and @Disabled annotations?

Tags:

junit

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.

like image 403
kc2001 Avatar asked Dec 13 '22 17:12

kc2001


1 Answers

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.

like image 187
emerssso Avatar answered Jun 21 '23 22:06

emerssso