我有下面的JUnit 4异常测试:
@Test(expected = NotFoundException.class)
public void getRecipeByIdTestNotFound() throws Exception {
Optional<Recipe> recipeOptional = Optional.empty();
when(recipeRepository.findById(anyLong())).thenReturn(recipeOptional);
Recipe recipeReturned = recipeService.findById(1L);
//should go boom
}
我希望得到有关在JUnit 5中测试相同内容的最有效方法的帮助。
1条答案
按热度按时间7kqas0il1#
用法一:
用法二: