我编写了一个API帮助程序类的junit测试用例,但是当我检查代码覆盖率时,帮助程序类显示为0%。我不确定是什么问题。
以下是示例代码:
public Class ClassHelper{
public Response invoke() {
ClassVO classVO = new ClassVO(pString);
ClassOutputVO outputVO = getSoapServiceBridgeProvider().getSoapServiceBridge(classVO).invokeProces()
...
return response
}
}
测试类如下:
@Test
public void testInvoke() throws Exception{
PowerMockito.whenNew(ClassVO.class).withArguments(Mockito.anyString()).thenReturn(mockVO);
Response actualResponse = (Response) classHelper.invoke();
有人可以帮我解决这个问题吗?它与其他帮助程序类一起工作,但只与api帮助程序一起发生。
工作示例如下:
@Component
public class TestHelper {
public Reponse updateRole(Request request) throws Exception {
ClassVO vo = new ClassVO();
vo.setRoleId(request.getRoleId());
vo.setRoleName(request.getRoleName());
Response response = new Response;
response.setRoleId(vo.getRoleId());
response.setRoleName(vo.getRoleName));
}
}
测试类:
@ContextConfiguration
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
@PrepareForTest({ DriverManager.class })
public class TestHelperTest {
@InjectMocks
private TestHelper testHelper;
@Test
public void testUpdateRole() throws ADTMBaseException{
Request request = new Request();
request.setRoleId(8);
request.setRoleName(JUnitTestConstants.ROLE_NAME);
Reponse actualResult = testHelper.updateRole(request);
}