Running specific Maven Test with JVM Args

21 09 2007

I have some long running tests in search, but I wouldnt want anyone to run them as part of the normal build. The tests dont have the word Test in the classname which prevents them from running, but they can be invoked on the command line with -Dtest=classname

mvn -Dtest=SearchSoak test

Also I have found that its necessary sometimes to add jvm args to the unit test, reconfiguring the Surefire plugin makes this possible, in the pom

...
  <properties>
    <deploy.target/>
    <maven.test.jvmargs> </maven.test.jvmargs>
  </properties>
...
<build>
...
 <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <forkMode>pertest</forkMode>
          <argLine>${maven.test.jvmargs}</argLine>
        </configuration>
      </plugin>
    </plugins>
...
</build>

And then to run with a heap dump and YourKit connection

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Applications/YourKit Java Profiler 6.0.16.app/bin/mac"mvn -Dtest=SearchSoak \
   -Dmaven.test.jvmargs='-XX:+HeapDumpOnOutOfMemoryError -agentlib:yjpagent' \
   test
Advertisements

Actions

Information

5 responses

30 01 2009
Eirik R. Larsen

Instead of specifying in settings.xml you can specify instead, which is read by the surefire plugin. That way you don’t need to configure the surefire plugin per project in pom.xml.

If you need to override the setting on the commandline you type

mvn clean install -DargLine=[jvm args]

Regards

16 04 2009
Yuen-Chi Lian

Hi there,

Thanks heaps.

yc

17 08 2012
Stan

Hi!
Is there a way to specify several properties like:

mvn2.1 test -DargLine=”-Dproperty=test -Dproperty2=test2″

Bacause when I’m trying to execute next code it returns not what I’m expected

System.out.println(System.getProperty(“property”)); // test -Dproperty2=test2

System.out.println(System.getProperty(“property2”)); // null

17 08 2012
Ian

This is a pure guess, but play around with quoting

mvn2.1 test -DargLine='-Dproperty="test" -Dproperty2="test2"'

might work, it looks like maven is interpreting

mvn2.1 test -DargLine="-Dproperty=test -Dproperty2=test2"

as

-Dproperty="test -Dproperty2=test2"

20 08 2012
Stan

Thank you for the reply. It is some parsing problem in TeamCity…
From the cmd it works fine,




%d bloggers like this: