Issue
I've got a Java Spring boot service that contains several modules.
When I do mvn test
in the root folder of the project I see about 400 tests running and all of them are OK.
Then in Intellij I make right click on my module and select Run All Tests
menu item. In this case 70% of tests start to fail. If I run a single test in Intellij by clicking a green triangle in front of the test it fails as well.
The problem seems to be some missing configuration or something like this.
If I create a maven run configuration in Intellij with clean install
command or if I run maven test
phase in the menu of Intellij I see that all tests are ok.
What may be the difference between mvn test
in command line and running test in Intellij that makes maven's tests pass and Intellij's fails?
Solution
What may be the difference between mvn test in command line and running test in Intellij that makes maven's tests pass and Intellij's fails?
Long story short : Maven in shell is the best judge. If it works with pure maven, track any differences between IDE and shell concerning Maven, JDK/JRE and ALL (compile, test...) classpath configuration. It may often help.
--
Broadly, I noticed three sources of possible differences of behavior between shell and IDE (IntelliJ as Eclipse) maven goal execution.
These two first are not test specific :
- Maven or JDK/JRE differences
Indeed Maven version/configuration or JDK/JRE version differences may produce different behaviors - Side effects specific to IDEs.
IDEs wrap the maven execution. That additional layer may set things as compile/test classpath. In case of bad IDE configuration or bug in the IDE related to that, the behavior in the IDE may differ with the behavior in shell.
This one is test-specific :
- Test Runners IDE plugins.
To run test classes, IDEs relies on their own plugin (for example Eclipse plugin for JUnit 4 or JUnit 5 or IntelliJ plugin for JUnit 4 or JUnit5).
These plugin may be misconfigured, bugged or lacked some dependencies in some specific configuration. For example Eclipse and IntelliJ plugins created for JUnit 5 didn't work smoothly for a long time and it may require us to add in the classpath some JUnit 5 platform launcher libraries to allow our IDEs to run unit tests.
These issues provoke generally a early error to launch tests.
Answered By - davidxxx