Re: Side effects between test cases
| Newsgroups | gmane.comp.java.junit.user |
|---|---|
| Message-ID | <[email protected]> |
Tobias Werth [email protected] [junit] wrote on 24.7.2014 23:49: > So what's the best practice to reduce or even avoid these side effects > when writing JUnit test methods? I don't worry about excess CPU and memory consumption when it only happens when tests fail. After the test run ends and the JVM is killed, those resources are automatically freed by the OS. And even if it starves the JVM so much that the test run will never end, it's possible to force kill the process manually. Just about the only resource I worry about is the file system. If the JVM is killed in the middle of a test run (e.g. because a test got stuck), the test might not clean up whatever files it created. This may result in many gigabytes of temporary files remaining in the OS's temporary directory. My workaround is to set the java.io.tmpdir system property to a temporary directory inside the project (e.g. target/tmp/ with Maven), so that it will be removed automatically when doing a clean build. -- Esko Luontola www.orfjackal.net ------------------------------------ Posted by: Esko Luontola <[email protected]> ------------------------------------