ass*_*ias 8 java junit hamcrest
我浏览了JUnit的ExpectedExceptions"javadoc的,我不明白的地方startsWith在他们的例子来自(代码标记HERE).我检查了CoreMatcher实用程序类,但找不到任何静态startsWith方法.
该方法在哪里?
(我显然可以自己写,但这不是重点)
public static class HasExpectedException {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void throwsNullPointerExceptionWithMessage() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("happened?");
thrown.expectMessage(startsWith("What")); //HERE
throw new NullPointerException("What happened?");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 9
import static org.hamcrest.core.StringStartsWith.startsWith;
Run Code Online (Sandbox Code Playgroud)
两者兼得
assertThat(msg, startsWith ("what"));
Run Code Online (Sandbox Code Playgroud)
和
ExpectedException.none().expectMessage(startsWith("What")); //HERE
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4982 次 |
| 最近记录: |