Is there a way to find the ignored JUnit Test with the most lines of code in a large codebase?

476 views Asked by At

This is a static analysis question. It might be possible to write an AST parser with the ANTLR plugin in Checkstyle - or the backend to Findbugs. I'm looking for a pre-existing solution.

We have a weekly meeting of our developers in which we talk about issues of the day. Part of this is looking at the code quality reports in Sonar.

We have a number of ignored JUnit tests we're working through - and I'd like to rank them by size (lines of code in the JUnit test method).

My question is: Is there a way to find the ignored JUnit Test with the most lines of code in a large codebase?

Here is an example of an ignored method in a JUnit test:

  import org.junit.Test;
  import org.junit.Ignore;
  import static org.junit.Assert.assertEquals;

  public class TestJunit {

     String message = "Robert";   
     MessageUtil messageUtil = new MessageUtil(message);

     @Ignore
     @Test
     public void testPrintMessage() {
        System.out.println("Inside testPrintMessage()");
        message = "Robert";
        assertEquals(message,messageUtil.printMessage());
     }

     @Test
     public void testSalutationMessage() {
        System.out.println("Inside testSalutationMessage()");
        message = "Hi!" + "Robert";
        assertEquals(message,messageUtil.salutationMessage());
     }

  }

Here is the documentation for the @Ignored annotation.

https://www.tutorialspoint.com/junit/junit_ignore_test.htm

Assumptions:

  • Simple line-count - counting whitespace is fine. (If a more sophisticated line-count is available that's great - but all I want is a consistent baseline for comparison).
  • @Ignored can apply to classes and methods - ideally I want both, but this question was originally about ignored methods - so I'll stick with that.
1

There are 1 answers

0
Liping Huang On

If you use the maven surefire reports plugin to collect all the test reports, actually the ignored tested are collected by default, just like the below screenshots show, and you can go through all the ignored tests details.

enter image description here

enter image description here