Я изменяю некоторые из моих тестовых случаев, чтобы начать использовать PowerMockito. Ниже приведен пример тестового класса, который я написал
@PrepareForTest({Setup.class})
public class TestSampleUtil {
@Rule
public PowerMockRule rule = new PowerMockRule();
@Mock
Setup fakeSetupClass;
@Before
public void init() {
fakeSetupClass = Mockito.mock(Setup.class);
PowerMockito.mockStatic(Setup.class);
PowerMockito.when(Setup.getInstance()).thenReturn(fakeSetupClass);
}
@Test
public void SampleUtil_defaultValues()
{
PowerMockito.when(Setup.getInstance().readIntConf(10)).thenReturn(1);
SampleUtil util = new SampleUtil(RuntimeEnvironment.application.getApplicationContext());
SampleUtilConfig sampleUtilConfig = util.getSampleConfigTest();
Assert.assertEquals(sampleUtilConfig.getSampleDataModel().getAllowFeature(), true);
}
Но каждый раз, когда я запускаю тестовый пример, я получаю следующее исключение:
java.lang.RuntimeException: Stub!
at org.xmlpull.v1.XmlPullParserFactory.newInstance(XmlPullParserFactory.java:117)
at com.thoughtworks.xstream.io.xml.XppDriver.createParser(XppDriver.java:57)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1085)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1076)
at org.powermock.classloading.DeepCloner.clone(DeepCloner.java:55)
at org.powermock.classloading.AbstractClassloaderExecutor.executeWithClassLoader(AbstractClassloaderExecutor.java:56)
at org.powermock.classloading.SingleClassloaderExecutor.execute(SingleClassloaderExecutor.java:67)
at org.powermock.classloading.AbstractClassloaderExecutor.execute(AbstractClassloaderExecutor.java:43)
at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:75)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Может кто-нибудь помочь мне разобраться, что может быть не так? Спасибо.