【发布时间】:2020-01-28 11:27:58
【问题描述】:
我在使用 Mockito 测试方法时遇到问题。 请检查 JunitTestCaseClass 的 testMethodToBeTested() 方法,该方法必须处理第三方类的静态方法调用。
class ClasssToBeTested{
public String methodToBeTested() {
String result = ThirdPartyUtilClass.methodToBeCall();
return result;
}
}
class ThirdPartyUtilClass{
public static String methodToBeCall(){
return "OK";
}
}
// JunitTestCase which will test method "methodToBeTested()" of ClasssToBeTested class
class JunitTestCaseClass{
@InjectMocks
private ClasssToBeTested classsToBeTested;
@Test
public void testMethodToBeTested() {
//How to handle ThirdPartyUtilClass.methodToBeCall(); statement in unit testing
String result = classsToBeTested.methodToBeTested();
Assert.assertNotNull(result);
}
}
请帮助并提前致谢。
【问题讨论】: