Robolectric a configuration tutorial on the Web, but I used it to configure it and foundUsethe Mockito.spy function will appear exception. Later on the Powermock official online found another tutorial, which said that using Powermockrule is not reliable, to use the Powermock 1.6.0 introduced by the new @powermockrunnerdelegate annotation to configure
The specific configuration file is as follows: module inside the Build.gradle add dependency:
dependencies {
......
testCompile "org.robolectric:robolectric:3.0"
testCompile ‘org.mockito:mockito-core:1.10.19‘
testCompile ‘junit:junit:4.12‘
testCompile "org.powermock:powermock-module-junit4:1.6.4"
testCompile "org.powermock:powermock-module-junit4-rule:1.6.4"
testCompile "org.powermock:powermock-api-mockito:1.6.4"
testCompile "org.powermock:powermock-classloading-xstream:1.6.4"
}
The following robolectrictest base class is inherited, and can be tested normally using Powermock and robolectric.
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
/**
* Base class extended by every Robolectric test in this project.
*/
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class,
sdk = 21)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
public abstract class RobolectricTest {
}
From for notes (Wiz)
Configure the unit test for Android using both Powermock and robolectric