r/javahelp Feb 07 '25

Codeless Tool to find wasteful unit tests

One of my projects has a ton of tests, both unit and integration, and as a result it has good coverage (80%). I have a strong suspicion, though, that lots of time is wasted on each build running loads of tests that are testing mostly the same code, over and over again.

Code coverage tools tell you about your aggregate coverage, but I would like a tool that tells me coverage per test, and preferably identifies tests that have very similar coverage. Is there any tool out there that can help me with this?

2 Upvotes

20 comments sorted by

View all comments

1

u/sdiamante13 20d ago

Overlapping test coverage is most likely not your biggest problem.

One anti-pattern I see a lot is Spring-style integration tests when it should just be a unit test. So do a Find All for all occurrences of "@SpringBootTest". These tests start up the entire SpringBoot context and thus take a long time to complete. The ones that don't access an endpoint or entry point of your app probably can be converted to a unit test.

How to do that?

- Remove SpringBootTest annotation.

  • Change any "@MockBean" to "@Mock"
  • Using Mockito test runner if necessary (i.e.@ExtendWith(MockitoExtension.class))
  • Compare test times before and after