Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Exception #3920

Closed
Rimjhim28 opened this issue May 27, 2018 · 4 comments
Closed

Runtime Exception #3920

Rimjhim28 opened this issue May 27, 2018 · 4 comments

Comments

@Rimjhim28
Copy link

Whenever I try to run the robolectric tests on my machine, I am facing a runtime exception.

Here the error log:

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

	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:174)
	at org.robolectric.shadows.ShadowAssetManager.reset(ShadowAssetManager.java:900)
	at org.robolectric.Shadows.reset(Shadows.java:1666)
	at org.robolectric.Robolectric.reset(Robolectric.java:40)
	at org.robolectric.android.internal.ParallelUniverse.resetStaticState(ParallelUniverse.java:44)
	at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:280)
	at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:203)
	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
	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.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
	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)
Caused by: java.lang.NoSuchFieldException: sSystem
	at java.lang.Class.getDeclaredField(Class.java:2070)
	at org.robolectric.util.ReflectionHelpers.setStaticField(ReflectionHelpers.java:172)
	... 25 more

Since the potential error lies in configuration, I am also posting the screenshots.

default configurations

junit configurations

Any help to fix the error is highly appreciated!

@jongerrish
Copy link
Contributor

jongerrish commented May 27, 2018 via email

@Rimjhim28
Copy link
Author

@jongerrish
The dependency I am using for robolectric is:

 testImplementation "org.robolectric:robolectric:3.3.2" 

One of the test class is:

package powerup.systers.com.powerup.test;

import android.os.Build;
import android.widget.TextView;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

import powerup.systers.com.AboutActivity;
import powerup.systers.com.BuildConfig;
import powerup.systers.com.R;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.robolectric.Shadows.shadowOf;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
public class AboutActivityTest {
    private AboutActivity activity;

    @Before
    public void setUp() {
        activity = Robolectric.buildActivity(AboutActivity.class)
                .create()
                .resume()
                .get();
    }

    @Test
    public void shouldNotBeNull() {
        assertNotNull(activity);
    }

    @Test
    public void clickingHomeButtonShouldFinishActivity() {
        activity.findViewById(R.id.homeButton).performClick();
        ShadowActivity activityShadow = shadowOf(activity);
        assertTrue(activityShadow.isFinishing());
    }

    @Test
    public void checkingTitleIsShownCorrectly() {
        TextView textView = (TextView) activity.findViewById(R.id.about_title);
        assertEquals(textView.getText().toString(),
                activity.getResources().getString(R.string.about_title));
    }

}

@paddykily
Copy link

A previously failed repository download could result in this issue.

  • Delete the existing roboelectric version in /home/user/.m2/repository/org/robolectric/android-all.
  • Re-run your tests (roboelectric will be re-downloaded in the process).

@jongerrish
Copy link
Contributor

What @paddykily says sounds very plausible. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants