Detecting JUnit "tests" that never claim anything

We used to have a technical director who loved to enter code, and also added unit tests with great enthusiasm. Unfortunately, his preferred test style was to draw some output on the screen and visually check the result.

Given that we have a large test bank, are there any tools or methods that I could use to identify tests that never claim?

+4
source share
3 answers

Since this is a one-time operation, I would:

  • scan all testing methods (easy, get jUnit XML report)
  • use the IDE or another to search for links to Assert. *, export result as a list of methods
  • awk / perl / succeed results to find inconsistencies

Edit: another option is to simply look for links to System.out or as its preferred way to output data; most tests will not have this.

+2
source

Not sure about the instrument, but the thought that comes to mind is doubled.

  • Create a TestRule class that tracks the number of statements per test (use a static counter, clear the counter at the beginning of the test, assert that it is not 0 at the end of the test).

  • Wrap the Assert class in your own proxy server, which increments the TestRule counter with every call.

Whether your Assert class is named Assert, you only need to update the import and add the rule to the tests. The above mechanism is not thread safe, so if you run several tests at the same time, you will get erroneous results.

+1
source

If these tests are the only ones that produce the output, automatically replace the System.out.println( volume System.out.println( using org.junit.Assert.fail("Fix test: " + will highlight exactly those tests that do not pull their weight. This method It makes it easier to test these tests in the IDE after launch and decides whether to fix or delete them; it also gives a clear idea of ​​progress.

+1
source

All Articles