Enforce messages for ignored JUnit tests

Enforce messages for ignored JUnit tests

Keine Kommentare zu Enforce messages for ignored JUnit tests

During the last days two posts Find JUnit assertions without a message and Find JUnit tests without assertions have been published here about useful rules regarding proper usage of JUnit.

Now a colleague came up with the hint that it would be very useful to ensure that every occurrence of the annotation @org.junit.Ignore shall provide a message why a particular test class or method is ignored:

  @Ignore // No message is provided
  public void test1() {

  @Ignore("Requires fix for ticket XYZ.")
  public void test2() {

The method „test1“ does not provide any context information why it has been disabled whereas „test2“ does. Thus for setting up a rule we need to find all annotations of type @org.junit.Ignore which do not have an attribute value named „value“:


    <constraint id="junit4:IgnoreWithoutMessage">
        <description>All @Ignore annotations must provide a message.</description>
              ignoreType.fqn= "org.junit.Ignore"
              and not (ignore)-[:HAS]->(:Value{name:"value"})
              e as IgnoreWithoutMessage


So this is another candidate for the jQAssistant JUnit4 plugin.

About the author:



Leave a comment

Back to Top