Tag: expected exception

如果抛出JUnit ExpectedException后如何继续测试?

我已经使用ExpectedExceptionfunction设置了一些JUnit(4.12)测试,我希望测试在预期的exception之后继续。 但我从来没有看到日志’3’,因为执行似乎在exception后停止,如果捕获事件? 这实际上是可能的,怎么样? @Rule public ExpectedException exception = ExpectedException.none(); @Test public void testUserAlreadyExists() throws Exception { log.info(“1”); // Create some users userService.createUser(“toto1”); userService.createUser(“toto2”); userService.createUser(“toto3”); Assert.assertTrue( userService.userExists(“toto1”) ); Assert.assertTrue( userService.userExists(“toto2”) ); Assert.assertTrue( userService.userExists(“toto3”) ); log.info(“2”); // Try to create an existing user exception.expect(AlreadyExistsException.class); userService.createUser(“toto1”); log.info(“3”); }