📜  jupiter spring boot 预期抛出的测试 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:44.899000             🧑  作者: Mango

代码示例1
@Test
public void whenExceptionThrown_thenAssertionSucceeds() {
    Exception exception = assertThrows(NumberFormatException.class, () -> {
        Integer.parseInt("1a");
    });

    String expectedMessage = "For input string";
    String actualMessage = exception.getMessage();

    assertTrue(actualMessage.contains(expectedMessage));
}