我被分配为将单元测试代码覆盖率添加到未使用IoC和0单元测试的15年旧传统项目。我不允许重构代码,因为它适用于生产精细完美,管理层不希望其他球队参与的重构如QA测试等doNothing方法不适用于无效静态方法
服务类有一个performService
方法如下代码
public void performService(requestMessage, responseMessage) {
UserAccount userAccount = requestMessage.getUserAccount();
GroupAccount groupAccount = requestMessage.getGroupAccount();
Type type = requestMessage.getType();
StaticServiceCall.enroll(userAccount, groupAccount, type);
response.setStatus(Status.SUCCESS);
}
This StaticServiceCall.enroll
method is calling remote services。我的单元测试是
@RunWith(PowerMockRunner.class)
@PrepareForTest(StaticServiceCall.class)
public class EnrollmentServiceTest {
@Test
public void testPerformService() {
mockStatic(StaticServiceCall.class);
doNothing().when(StaticServiceCall.enroll(any(UserAccount.class), any(GroupAccount.class), any(Type.class)));
service.performService(requestMessage, responseMessage);
assertEquals("Enrollment should be success, but not", Status.SUCCESS, response.getStatus);
}
的Eclipse与The method when(T) in the type Stubber is not applicable for the arguments (void)
的Eclipse停止抱怨抱怨,如果测试代码改变
mockStatic(StaticServiceCall.class);
doNothing().when(StaticServiceCall.class);
StaticServiceCall.enroll(any(UserAccount.class), any(GroupAccount.class), any(Type.class));
service.performService(requestMessage, responseMessage);
assertEquals("Enrollment should be success, but not", Status.SUCCESS, response.getStatus);
测试用例UnfinishedStubbingException
失败。我正在使用powermock 1.6.6