mercredi 27 juillet 2016

Testing NoClassDefFoundError rx/Observable$OnSubscribe

I'm trying to learn how to use Robolectric to do test on my app, but I'm facing the next problem.

ERROR

Downloading: org/robolectric/android-all/4.1.2_r1-robolectric-0/android-all-4.1.2_r1-robolectric-0.jar from repository sonatype at http://ift.tt/1266f41
Transferring 30702K from sonatype
Downloading: org/robolectric/shadows-core-v16/3.1.1/shadows-core-v16-3.1.1.jar from repository sonatype at http://ift.tt/1266f41
Transferring 2581K from sonatype

java.lang.NoClassDefFoundError: rx/Observable$OnSubscribe

    at com.testingex.timeexpensestool.TETApplication.onCreate(TETApplication.java:30)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:152)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:237)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:174)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:63)
    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:140)
    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:69)
    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.ClassNotFoundException: rx.Observable$OnSubscribe
    at org.robolectric.internal.bytecode.InstrumentingClassLoader.getByteCode(InstrumentingClassLoader.java:192)
    at org.robolectric.internal.bytecode.InstrumentingClassLoader.findClass(InstrumentingClassLoader.java:147)
    at org.robolectric.internal.bytecode.InstrumentingClassLoader.loadClass(InstrumentingClassLoader.java:122)
    ... 21 more


java.util.ServiceConfigurationError: org.robolectric.internal.ShadowProvider: Provider org.robolectric.shadows.support.v4.Shadows not a subtype

    at java.util.ServiceLoader.fail(ServiceLoader.java:239)
    at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.robolectric.internal.bytecode.InstrumentationConfiguration$Builder.build(InstrumentationConfiguration.java:151)
    at org.robolectric.RobolectricTestRunner.createClassLoaderConfig(RobolectricTestRunner.java:118)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:172)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:63)
    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:140)
    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:69)
    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)

My test is the next:

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, application = TETApplication.class, sdk = Build.VERSION_CODES.JELLY_BEAN)
public class LoginActivityTest {

    private LoginActivity activity;

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

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void testLogin() throws Exception {

    }

    @Test
    public void testEmail() throws Exception {

        activity = Robolectric.setupActivity(LoginActivity.class);

        EditText etEmail = (EditText) activity.findViewById(R.id.login_email);
        ActionProcessButton apbtLogin = (ActionProcessButton) activity.findViewById(R.id.btn_login);

        etEmail.setText("maol@thisismymail.com");
        apbtLogin.performClick();
        assertNotNull(etEmail.getText());
    }
}

The custom application class, is:

public class TETApplication extends MultiDexApplication {

    private static TETApplication singleton;

    public static TETApplication getInstance() {
        return singleton;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        singleton = this;

        Hawk.init(this)
                .setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
                .setStorage(HawkBuilder.newSqliteStorage(this))
                .setLogLevel(LogLevel.FULL)
                .build();

        Dexter.initialize(getApplicationContext());
    }

    @Override
    protected void attachBaseContext(Context base) {
        try {
            super.attachBaseContext(base);
            MultiDex.install(this);
        } catch (Exception e) {
            String vmName = System.getProperty("java.vm.name");
            if (!vmName.startsWith("Java")) {
                throw e;
            }
        }
    }
}

I'm using a library to store variables called "Hawk", I don't know if this is the problem.

Thanks

Aucun commentaire:

Enregistrer un commentaire