Tests failing in Maven install from command line but passing from Eclipse UI
Solution 1
If your tests are failing using maven command line then rest asure there is a problem with your test. You can't rely on eclipse, or rather m2Eclipse, for this because m2eclipse is not able to provide you with a correct classpath.
For instance, in eclipse you can refer from a class in src\main\java to a class in src\test\java, you won't get any compilation error. Of course, in maven (or an IDE with a decent maven integration like intelliJ) compilation will fail, as it should. Running tests in eclipse is fine (quicker/easier than maven command line) but the actual test you must perform (before committing to svn for instance) is to do a clean install with maven command line.
UPDATE
To address your question: src/main/resources is in the classpath when maven (surfire) runs the tests
Solution 2
I had the same problem, tests are all ok in Eclipse with JUnit, but fail in maven when I do mvn test
in the console.
I solved this issue adding
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
to my pom.xml
.
Arry
An eternal student of Computer Science. Senior Data Engineer @ Intuit
Updated on June 04, 2022Comments
-
Arry almost 2 years
I am using Maven in my Java project and the IDE is Eclipse. I have few test cases in my project, and when I am doing a Maven Install from eclipse then my test cases are passing, but when I am doing the Maven install from the command line, then all my test cases are failing. I have the following directory structure for my project: src/ main/ java/ resources/ test/ java/ resources/
Also, for my test cases, I have to use few configs from main/resources. I suspect that while running test cases from the command line (mvn clean install), it is not looking for the resources in main/resources and so is the error.
Can anyone please tell that how can I ask maven to look for the configs in main/resources also for my test cases? Also, if you suspect that the error is something else then please comment.
Thanks.