Why some tests fail when mvn clean install but not when I run them individually?

Viewed 34

So recently, I migrated from java 11 to 17 my project and suddenly some of my tests started to fail after executing mvn clean install command with a 500 internal error. I wanted to debug one of the individual tests that fails to detect the problem and for my surprise when I run the command mvn -Dtest=TestClass#whenXthenY test the test passes.

When I run mvn clean install from the IDE it works as well.

I have no clue what could be happening here. The project is a Spring Boot project. Any idea what could be the reason of this behaviour?

1 Answers

You probably have some test leakage (data being kept between tests), so the order of the tests might matter, and might be changed between the java-versions. This can be static variables, stuff that gets stored / loaded from disk or external services, etc. etc.

Do you run them in parallel? Else you could check if the execution order of the tests are the same or not.

This is very hard to debug; the main thing is to check first if tour test are really well isolated or not.

Related