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
I agree with the others who said that there is no simple way to distribute these settings.
For Eclipse: ask your colleagues to set the following:
-Xmx1024m
After that all test will run with -Xmx1024m
but unfortunately you have set it in every Eclipse installation. Maybe you could create a custom Eclipse package which contains this setting and give it to you co-workers.
The following working process also could help: If the IDE cannot run a test the developer should check that Maven could run this test or not.
In IntelliJ you can specify default settings for each run configuration. In Run/Debug configuration dialog (the one you use to configure heap per test) click on Defaults and JUnit. These settings will be automatically applied to each new JUnit test configuration. I guess similar setting exists for Eclipse.
However there is no simple option to transfer such settings (at least in IntelliJ) across environments. You can commit IntelliJ project files to your repository: it might work, but I do not recommend it.
You know how to set these for maven-surefire-plugin
. Good. This is the most portable way (see Ptomli's answer for an example).
For the rest - you must remember that JUnit test cases are just a bunch of Java classes, not a standalone program. It is up to the runner (let it be a standalone JUnit runner, your IDE, maven-surefire-plugin
to set those options. That being said there is no "portable" way to set them, so that memory settings are applied irrespective to the runner.
To give you an example: you cannot define Xmx
parameter when developing a servlet - it is up to the container to define that. You can't say: "this servlet should always be run with Xmx=1G
.