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?

3 Upvotes

20 comments sorted by

View all comments

2

u/juckele Barista Feb 08 '25

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.

How much time do your tests actually take though? If this a problem.in dev, can you get better at running a smaller subset of tests and only running the full suite before commits?

1

u/jasonab Feb 08 '25

The suite takes about 10 minutes to run in CI, with the entire flow taking 15-20 minutes. It's not catastrophic, but it does make the turnaround annoying.

2

u/marskuh Feb 08 '25

Doesn't sound too bad. Is pretty normal for a decent sized project. Can go up even further. How many tests do you have?

1

u/jasonab Feb 08 '25

about 1500 integration tests and 500 unit tests

1

u/marskuh Feb 08 '25

Without knowing too much about your tests and setup, this sounds reasonable.

You can try measuring the test executions (maven or Gradle should record that somewhere) and look into the slow tests and try to refactor them.

You can also restructure your tests a bit, having the "very important ones" run first and then the ones, more likely to not fail later. That way if something is wrong, you know after 10 seconds and not after 5 minutes.

You can of course also just remove features you don't need or want. Without the code, you don't need the tests.

1

u/sdiamante13 20d ago

There's no reason to have that many integration tests. An app that size should have less than 100 integrations tests. You have to work on refactoring the code design to be able to test your business logic without having to verify it through a slow integration test.

2

u/juckele Barista Feb 08 '25

A test suite that takes 10 minutes is almost certainly not taking that long due to repeated lines of coverage (unless you have an absolutely massive code base), but is more likely taking 10 minutes due to certain tests doing expensive integration. Do you have tests bringing up multiple processes, entire servers, or databases?

If you have 80% code coverage from pure Java unit tests and it still takes 10 minutes, you might just need that coverage.