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.
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.
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”.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With