【发布时间】:2023-04-08 19:56:01
【问题描述】:
我有一个控制器和一些方法,它会抛出 CustomException:
@GetMapping
ResponseEntity<Void> getOriginalUrl() {
...
throw new CustomException("my message");
...
}
我想测试一下。 测试:
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testGetOriginalUrl() throws Exception {
mvc.perform(get(...)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
thrown.expect(CustomException.class);
thrown.expectMessage("my message");
}
但它不起作用。如何测试?
【问题讨论】:
标签: java spring testing junit mocking