Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JVM parameters for Junit Unit Tests?

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 sufficient heap-space, and will be run internally on Win 7 64-bit machines - so redesigning the tests isn't a practical suggestion.)

I am developing in Intellij IDEA, so I know I can set the JVM parameters (e.g. -Xmx1024M) for the test class. However, this is only for running the whole test class - if I want to run an individual test, I have to recreate the run congfigurations for that test method.

Also, those are IDE and box specific - so if I switch boxes (I develop on multiple machines) or one of my colleagues tries to run the tests, those settings are not transferred. (Also, other IDEs like Eclipse and NetBeans are used by my colleagues.) FWIW, we're using mercurial for source code control.

For the build cycle, we're using Maven, so I know how to specify the JVM parameters for that.

So: - I'm looking for a way of specifying the JVM parameters that will apply for the whole test class and the individual test methods; and - I'd like to share those specification across IDEs on any machine (having picked up the code from the repository).

like image 618
amaidment Avatar asked Sep 28 '11 07:09

amaidment


People also ask

Where do I put JVM parameters?

To add JVM parameters, choose New . The property is added to Custom parameters . The actual parameters used by a running JVM can be found in the development trace file of the corresponding server process. This results in parameter: "-agentlib:myagent=port=12345,dir=C:/Mydir" .

What are the JVM parameters?

JVM has four types of GC implementations: Serial Garbage Collector. Parallel Garbage Collector. CMS Garbage Collector.

Can JUnit test method have parameters?

JUnit allows you to use parameters in a tests class. This class can contain multipletest methods and each method is executed with the different parameters provided. It helps developers save time when executing the same tests which differ only in their inputs and expected results.


1 Answers

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.

like image 135
ptomli Avatar answered Sep 27 '22 22:09

ptomli