Will proposes in the comments using System Rules, a collection of JUnit(4.9+) rules for testing code which uses. ![]() Public void testNoExit() throws ExceptionĪssertEquals("Exit status", 42, e.status) tSecurityManager(null) // or save and restore original tSecurityManager(new void tearDown() throws Exception allow void checkPermission(Permission perm, Object context) Private static class NoExitSecurityManager extends void checkPermission(Permission perm) Protected static class ExitException extends SecurityException public class NoExitTestCase extends TestCase Try modifying the TestCase to run with a security manager that prevents calling System.exit, then catch the SecurityException. Prevent System.exit() to actually exit the JVM:. ![]() Such-and-such test failed and move smoothly along to the next. In the JUnit scenario it will be caught by the JUnit framework, which will report that Instead of terminating with System.exit(whateverValue), why not throw an unchecked exception? In normal use it will drift all the way out to the JVM's last-ditch catcher and shut your script down (unless you decide to catch it somewhere along the way, which might be useful someday).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |