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

Time:09-27

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?

CodePudding user response:

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.

CodePudding user response:

The error was that I had two dependencies for the same thing (overlapping) and when I upgraded to Java 17 one of them wasn't working.

Then depending where I was running the tests from, It was taking one dependency or the other.

I removed the redundant dependency that was not working and that fixed everything.

  • Related