Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Eclipse unit test configuration

I use Eclipse and for some of my unit tests, I need to set some JVM args for the test to work, -Djava.library.path in particular. I set it in my POM file as follows:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Djava.library.path=target/dll</argLine>
  </configuration>
</plugin>

and it works correctly when I build with Maven. However, when I run in Eclipse (even with the Maven plug-in installed - I have everything else in my Eclipse environment working properly with maven), this JVM argument is not applied. Does anyone know why this is or how to fix this?

like image 802
Jeff Storey Avatar asked Jul 07 '09 20:07

Jeff Storey


People also ask

How do I run a Maven JUnit test in Eclipse?

you can run Junit 4 with Maven. You just need the Junit 4 dependency in your pom. You also need the surefire plugin to execute the tests. Hint: By default surefire looks for files with *Test.

How can JUnit be implemented using Maven?

The Maven Surefire Plugin 2.22. 0 (or newer) provides native support for JUnit 5. If we want to use the native JUnit 5 support of the Maven Surefire Plugin, we must ensure that at least one test engine implementation is found from the classpath. We can run our unit tests by using the command: mvn clean test.

How do I run a single test file in Maven Eclipse?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.


1 Answers

Running the test in Eclipse with the JUnit test runner does not invoke maven , even if you are using m2eclipse.

I suggest you either:

  • create a maven launch configuration for the test goal;
  • add -Djava.library.path=target/dll to your JVM arguments in the JUnit launch configuration.
like image 78
Robert Munteanu Avatar answered Oct 22 '22 06:10

Robert Munteanu