Tests failing in Maven install from command line but passing from Eclipse UI

Arry picture Arry · Jan 18, 2012 · Viewed 10.5k times · Source

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.

Answer

Stijn Geukens picture Stijn Geukens · Jan 18, 2012

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