【发布时间】:2019-07-29 15:53:44
【问题描述】:
我正在尝试使用存根方法来实施单元测试。 但是,当我存根该方法时,测试类没有行覆盖。
服务类
@Service
@Slf4j
public class Service {
@Autowired
private Client client;
private String doclinkUrl = "www.website.com"
public byte[] downloadContent(String objectId) {
String url = doclinkUrl + "documents/" +objectId + "/binary";
return client.target(url).request().get(byte[].class);
}
}
存根服务类
public class ServiceStub extends Service {
@Override
public byte[] downloadContent(String objectId) {
return "test".getBytes();
}
}
测试服务类
@RunWith(MockitoJUnitRunner.class)
public class ServiceTest {
@InjectMocks
private Service testee;
@Test
public void testDownloadContent(){
testee = new ServiceStub();
Assert.assertNotNull(testee.downloadContent("objectId"));
}
}
【问题讨论】:
-
你在使用
spring-boot吗?
标签: java unit-testing junit mockito stubbing