我有一个简单的 Java
方法,我想检查它是否不会抛出任何 exceptions
。
我已经模拟了参数等,但是我不确定如何使用 Mockito
来测试该方法没有抛出异常?
当前测试代码:
@Test
public void testGetBalanceForPerson() {
//creating mock person
Person person1 = mock(Person.class);
when(person1.getId()).thenReturn("mockedId");
//calling method under test
myClass.getBalanceForPerson(person1);
//How to check that an exception isn't thrown?
}
原文由 java123999 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果捕获到异常,则测试失败。