且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-20 10:20:34

你不能这样做,当抛出异常,抛出真实的 ExpectedException 规则。

You cannot do that, when the exception is thrown it's thrown for real, ExpectedException rule or not.

如果你真的想要这种行为,你可以回到旧学校模式:

If you really want this kind of behaviour, you can go back to the "old school" pattern:

try {
    userService.createUser("toto1");
    Assert.fail("expecting some AlreadyExistsException here")
} catch (AlreadyExistsException e) {
    // ignore
}

log.info("3");

但我不会费心去做一些日志。

But I wouldn't bother for some log.