Robolectric java.lang.NoSuchFieldException: sSystem

While doing UnitTest with robolectric I get the error

java.lang.NoSuchFieldException: sSystem

Please give me some advice.

enter image description here

Description

Integrated robolectric error

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchFieldException: sSystem

at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:332)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:259)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:41)
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.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:199)
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:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
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.AppMain.main(AppMain.java:144)
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: sSystem
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:174)
at org.robolectric.shadows.ShadowAssetManager.reset(ShadowAssetManager.java:780)
at org.robolectric.Shadows.reset(Shadows.java:1644)
at org.robolectric.Robolectric.reset(Robolectric.java:35)
at org.robolectric.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:52)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:319)
... 19 more
Caused by: java.lang.NoSuchFieldException: sSystem
at java.lang.Class.getDeclaredField(Class.java:2070)
at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:172)
... 24 more

      

Steps to reproduce

Robolectric and Android version

compileSdkVersion 25
buildToolsVersion "25.0.2"
minSdkVersion 15
targetSdkVersion 25
testCompile 'org.robolectric:robolectric:3.2.2'

      

+3


source to share


1 answer


I had this in kotlin test and fixed it by opening my test class:

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [23], constants = BuildConfig::class)
open class MyExampleTest {

      



Applies to java, this means your test class should not be final

...

0


source







All Articles