mercredi 13 décembre 2017

Android ExampleInstrumentedTest failing for flavors

I'm working on test Android app, default PackageName is com.kagarlickij.myapplication

My 'development' and 'staging' productFlavors add applicationIdSuffix, so PackageName for staging app is com.kagarlickij.myapplication.**staging**

When I run ./gradlew connectedStagingDebugAndroidTest I'm getting this exception:

    > Task :app:connectedStagingDebugAndroidTest
Starting 1 tests on Nexus_5X_API_27(AVD) - 8.1.0

com.kagarlickij.myapplication.ExampleInstrumentedTest > useAppContext[Nexus_5X_API_27(AVD) - 8.1.0] FAILED 
        org.junit.ComparisonFailure: expected:<...lickij.myapplication[]> but was:<...lickij.myapplication[.staging]>
        at org.junit.Assert.assertEquals(Assert.java:115)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedStagingDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/kagarlickij/Repos/public/MyApplication/app/build/reports/androidTests/connected/flavors/STAGING/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 12s
50 actionable tasks: 7 executed, 43 up-to-date

Default ExampleInstrumentedTest.java:

package com.kagarlickij.myapplication;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://ift.tt/2oljQWD">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.kagarlickij.myapplication", appContext.getPackageName());
    }
}

build.gradle - http://ift.tt/2BgXJen

How ExampleInstrumentedTest.java can be changed to support PackageNames from flavors?

Aucun commentaire:

Enregistrer un commentaire