相关疑难解决方法(0)

如何使用JUnit Test注释断言我的异常消息?

我已经用@Test注释编写了一些JUnit测试.如果我的测试方法抛出一个已检查的异常,并且我想要将该消息与异常一起断言,那么有没有办法使用JUnit @Test注释?AFAIK,JUnit 4.7不提供此功能,但未来的版本是否提供此功能?我知道在.NET中你可以断言消息和异常类.寻找Java世界中的类似功能.

这就是我要的:

@Test (expected = RuntimeException.class, message = "Employee ID is null")
public void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() {}
Run Code Online (Sandbox Code Playgroud)

java testing annotations junit4 assertion

286
推荐指数
8
解决办法
18万
查看次数

标签 统计

annotations ×1

assertion ×1

java ×1

junit4 ×1

testing ×1