Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven surefire arguments when running JUnit test via eclipse

A newbie question on Maven - Surefire - Eclipse - JUnit

I have configured the maven-surefire-plugin in the pom file of my project to pass some additional JVM arguments as below:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin.version}</version>
            <configuration>
                <argLine>-d64 -Xms128m -Xmx4096m -XX:PermSize=512m -Duser.timezone=UTC -XX:-UseSplitVerifier</argLine>
            </configuration>
        </plugin>

When I run a test case of this project from Eclipse as Run As->JUnit Test, though the classpath is correctly set, the additional arguments specified in the argLine are not included in the invocation. I have to go and manually key in the arguments under the relevant Debug Configurations. I don't quite understand how JUnit is aware that it needs to put jars of the test scope on the classpath and in some way means that JUnit tool in Eclipse is aware of Maven via M2E? If so, how can we make it also read argLine. I know this sounds very specific - but how do others manage in similar situations?

Thanks in advance!

like image 796
Kilokahn Avatar asked Sep 12 '12 16:09

Kilokahn


People also ask

How do I run a JUnit test case in Maven?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.

Which is the Maven plugin for running JUnit tests?

Running a Single Test Class The JUnit Platform Provider supports the test JVM system property supported by the Maven Surefire Plugin. For example, to run only test methods in the org. example.


1 Answers

Eclipse JUnit Launcher (choose Run As -> JUnit Test) is a independent test runner which has its own pre-defined build and running life cycle and has nothing to do with Maven, it will not pick up your pom magically and read in the surefire configuration and use them to drive the test running.

If your project is imported as an existing Maven project, use Maven (choose Run as -> Maven test) launch your JUnit test which will pick up and use the surefire configuration. This is exactly same as running mvn test from commandline, it only output run log in console and you will not able to use the nice red & green JUnit UI window.

Hope this make sense.

like image 149
yorkw Avatar answered Nov 11 '22 12:11

yorkw