简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM