【发布时间】:2020-11-20 01:53:43
【问题描述】:
我将 Mockito 与 Junit5 以及 SpringBootTest 一起使用。我需要断言抛出的异常及其消息。
【问题讨论】:
标签: java mockito junit5 spring-boot-test
我将 Mockito 与 Junit5 以及 SpringBootTest 一起使用。我需要断言抛出的异常及其消息。
【问题讨论】:
标签: java mockito junit5 spring-boot-test
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
@SpringBootTest
class Sample{
@Autowired
TestService service;
@Test
void sampleTest(){
Executable exec = ()-> service.execute();
Throwable thrown = assertThrows(MyException.class, exec, "Type your message");
assertEquals("Dancing stars", thrown.getMessage());
}
}
请参考文档here。
【讨论】: