Search code examples
javatestingjunitdecorator

Java and JUnit, find missing @Test decorators


Let's say we have a project full of unit tests (thousands) and they all should look like this

@Test
public void testExceptionInBla() {
   // some test
}

But in one case someone forgot to put an @Test decorator on top of the test.

What would be an easy way to spot those tests, without looking through all the code manually?

I want to find code like this, it's a test without @Test:

public void testExceptionInBla() {
   // some test
}

Solution

  • I were you I would look at some Sonar rule here I found something that may can match requirement:

    https://rules.sonarsource.com/java/RSPEC-2187