Java Runnable运行的JUnit测试用例

时间:2018-11-15 05:37:59

标签: java multithreading junit mockito runnable

即使有例外,我也希望程序运行正常。下面这样做。有人可以帮我编写JUnit测试用例吗?

TestClass

1 个答案:

答案 0 :(得分:0)

@Test方法引发异常将导致该异常以错误结束,但这并不成功。因此,针对此类情况的教科书方法是仅设置条件,运行该方法,并假设在异常不会导致测试出错的情况下一切正常:

@Test
public void testMyLogic() {
    // Set up conditions that would cause an the Runnable's body to throw an exception
    myMethod.run();

    // If we got here an exception was NOT thrown.
    // Implicitly, we're OK.
}