项目结构:Spring boot+Dubbo+Zookeeper+PowerMock
为了在项目中更好地编写单元测试,在项目中引入了PowerMock做单元测试。
例子
先看一个正常例子:Spring boot+PowerMock
包依赖如下:
testCompile "org.powermock:powermock-api-mockito2:1.7.1"
testCompile "org.powermock:powermock-module-junit4:1.7.1"
testCompile "org.mockito:mockito-core:2.8.47"
testCompile "org.hamcrest:hamcrest-library:1.3"
Service服务,即我要测试的类和函数:
@Service
public class MyService {
@Autowired
private MyRepository myRepository;
public Boolean needPopupWindow(Long id) {
// ... 省略其他
return myRepository.count(myExample) > 0;
}
// ... 省略其他
}
在其内部调用了 MyRepository的函数
public interface MyRepository {
long count(MyExam