我有一个最后的课,类似这样:
public final class RainOnTrees{
public void startRain(){
// some code here
}
}
Run Code Online (Sandbox Code Playgroud)
我在其他类中使用此类,如下所示:
public class Seasons{
RainOnTrees rain = new RainOnTrees();
public void findSeasonAndRain(){
rain.startRain();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的JUnit测试类中,Seasons.java我想模拟这个RainOnTrees类.我怎么能和Mockito一起做这件事?
嗨,我正在尝试模拟最后一个类(默认情况下,kotlin中的所有类都是最终类),并在gradle中添加了以下依赖项:
testImplementation 'junit:junit:4.12'
testImplementation 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.10'
testImplementation "org.mockito:mockito-android:2.13.0"
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation "org.mockito:mockito-core:2.13.0"
//testImplementation 'io.mockk:mockk:1.8'
testImplementation 'org.assertj:assertj-core:3.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "org.mockito:mockito-core:2.13.0"
androidTestImplementation "org.mockito:mockito-android:2.13.0"
androidTestImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
Run Code Online (Sandbox Code Playgroud)
该模仿内联应该使您能够模拟最终的kotlin类,因此我使用testImplementation和androidTestImplementation将其添加到我的Java单元测试和仪器测试中
在构建项目时,出现以下错误:
More than one file was found with OS independent path 'mockito-extensions/org.mockito.plugins.MockMaker'
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?如果我删除了类内联的androidTestImplementation,它可以正常编译,但是在运行仪器测试时,我收到了类比错误,说它无法模拟最终类。