I have some Junit unit tests that require a large amount of heap-space to run - i.e. 1G. (They test memory-intensive functionality for a webstart app that will only run with
According to this support question https://intellij-support.jetbrains.com/hc/en-us/community/posts/206165789-JUnit-default-heap-size-overridden-
the -Xmx argument for an IntelliJ junit test run will come from the maven-surefire-plugin, if it's set.
This pom.xml snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
seems to pass the -Xmx1024 argument to the junit test run, with IntelliJ 2016.2.4.
If you set it in Java code, you can set it like this
static {
System.getProperties().setProperty("env", "test");
System.getProperties().setProperty("spring.application.name", "spring-example");
}
reference:
https://stackoverflow.com/a/60654275/4712855
https://stackoverflow.com/a/10774432/4712855
In Maven you can configure the surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<argLine>-Xmx256M</argLine>
</configuration>
</plugin>
If you use Maven for builds then this configuration will be carried in the source tree and applied when tests are carried out. See the Maven Surefire Plugin documentation.
An eclipse specific alternative limited to the java.library.path JVM parameter allows to set it for a specific source folder rather than for the whole jdk as proposed in another response:
For those interested on detail on why maven argline tag should be preferred to the systemProperties one, look, for example:
Pick up native JNI files in Maven test (lwjgl)
Parameters can be set on the fly also.
mvn test -DargLine="-Dsystem.test.property=test"
See http://www.cowtowncoder.com/blog/archives/2010/04/entry_385.html
You can use systemPropertyVariables (java.protocol.handler.pkgs is your JVM argument name):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<systemPropertyVariables>
<java.protocol.handler.pkgs>com.zunix.base</java.protocol.handler.pkgs>
<log4j.configuration>log4j-core.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html