【发布时间】:2013-11-27 19:56:58
【问题描述】:
在一个 junit 类中,我想测试是否引发了异常,如果没有,提供一条解释性消息,建议在测试失败时要查找的内容。所以,类似...
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("an exception message");
thrown.failureMessage("This method should not be called directly. Be sure to use a subclass or mock that implements the method foo()");
显然,没有failureMessage()这样的方法。我不可能是世界上唯一一个想要实现失败消息的人。我在搜索的任何地方都没有找到示例。
请注意,这是参考 Junit4 @Rule 和 ExpectedException 功能。
【问题讨论】:
标签: java junit expected-exception