Luci
Luci

Reputation: 105

How to run tests with JUnit and Ant? In the same JVM or different JVM?

I am facing a small problem with JUnit and Ant. I do not know how I should run tests. Should I use the forked="yes" option witch make a new VM for each test,or should I use the same VM?

Which is the better way, or how do I know when to use the same JVM or not?

Thanks

Upvotes: 0

Views: 983

Answers (1)

M A
M A

Reputation: 72844

To run JUnit tests in Ant use the junit task. There is an option to run the tests in a separate JVM (the fork attribute).

In general, it is better to run the tests in a separate VM to isolate them from the Ant JVM and its classpath. This also allows to configure properties of the JVM for the tests, like the maximum amount of memory (many attributes of the task are only applied if fork is enabled).

However, this makes the tests take longer because of the overhead of creating a new JVM. This also depends on the forkmode attribute. If set to perTest, each test will run in its own VM.

forkmode

Controls how many Java Virtual Machines get created if you want to fork some tests. Possible values are "perTest" (the default), "perBatch" and "once". "once" creates only a single Java VM for all tests while "perTest" creates a new VM for each TestCase class. "perBatch" creates a VM for each nested and one collecting all nested s.

Upvotes: 2

Related Questions