11

As mentioned in here we can run test methods using,

mvn -Dtest=TestCircle#xyz test

But I need to set some JVM arguments before run the test case. Like I need to use

-Djava.security.manager -Djava.security.policy=mypolicy.policy

How can I tell maven to consider those when running a test case.

Community
  • 1
  • 1
prime
  • 14,464
  • 14
  • 99
  • 131
  • Possible duplicate of [Is there a way to pass jvm args via command line to maven?](http://stackoverflow.com/questions/12525288/is-there-a-way-to-pass-jvm-args-via-command-line-to-maven) – Manuel Spigolon Jan 10 '17 at 16:32
  • @Eomm so how can we use that to pass VM args when running test cases – prime Jan 10 '17 at 16:33
  • As suggested, you could use an envitoment variable called MAVEN_OPTS http://maven.apache.org/configure.html – Manuel Spigolon Jan 10 '17 at 16:36
  • http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html. – Tunaki Jan 10 '17 at 16:43
  • the surefire plugin creates its own process. You can use -DargLine="" to pass additional arguments to that new process: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#argLine – wemu Jan 10 '17 at 16:48

1 Answers1

12

Two possible solutions:

First, if your JVM arguments are applicable to all tests, you can add such information as a configuration item for Surefire as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    ...
    <configuration>
        <argLine>-Djava.security.manager -Djava.security.policy=mypolicy.policy</argLine>
    </configuration>
</plugin>

Second, if such JVM arguments are to be applied on a test-by-test basis, they can be specified on the command line as follows:

mvn -Dtest=TestCircle#xyz test -DargLine="-Djava.security.manager -Djava.security.policy=mypolicy.policy"
Frelling
  • 3,287
  • 24
  • 27