mardi 25 octobre 2016

NoSuchMethodError: No virtual method but method exists

I wrote a test for one of the classes in my app, which were created by myself. One of the methods in my Prefs class looks like this, nothing special:

public String getApiVersion() {
    return mPreferences.getString(API_VERSION, null);
}

My test looks like this:

@Test
public void testConfigValues() throws Exception {
    String url = mPrefs.getBaseUrl();
    assertNotNull("base url is null", url);

    // check tracking config
    assertNotNull(mPrefs.getTrackingLevel1());
    assertNotNull(mPrefs.getTrackingSubdomain());

    // api
    String apiVersion = mPrefs.getApiVersion();
    assertNotNull("API version is not null", apiVersion);
}

When I try to run the test, it fails and this is the output of the log:

java.lang.NoSuchMethodError: No virtual method getApiVersion()Ljava/lang/String; in class Lcom/myapp/mobile/utils/Prefs; or its super classes (declaration of 'com.myapp.mobile.utils.Prefs' appears in /data/app/com.myapp.android.news.test-2/base.apk)
at com.myapp.mobile.utils.PrefsTest.testConfigValues(PrefsTest.java:77)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
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.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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 org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1873)

I don't understand why this happens. All other methods of this class can be found. Only getApiVersion() can not be found.

Aucun commentaire:

Enregistrer un commentaire