我正在使用TestNG,EasyMock和PowerMock进行测试。根据下面的代码,我试图模拟从测试中的静态方法(fetchAuthenticator)调用的静态方法。当我运行测试时,在调用EasyMock.expect时会执行executeHttpGet方法。
@PrepareForTest(Metadata.class)
public class MetadataTest extends PowerMockTestCase {
@Test
public void testPatience(){
PowerMock.mockStatic(HttpHelper.class);
EasyMock.expect(
HttpHelper.executeHttpGet(EasyMock.anyString()))
.andReturn(
"{\"response\":\"some_value\"}");
PowerMock.replay(HttpHelper.class);
String response = Whitebox.invokeMethod(Metadata.class,
"fetchAuthenticator",
"something-else",
"somesite.com", "another-value");
assertNotNull(response);
}
}
我发现了类似的问题,但没有答案。 EasyMock: Actual function gets called while passing as an argument to EasyMock.expect
答案 0 :(得分:0)
你忘了包括:
@RunWith(PowerMockRunner.class)
在测试用例的类级别
并替换
@PrepareForTest(Metadata.class)
与
@PrepareForTest({ AuthenticationMetadata.class, HttpHelper.class })