2017-12-13 24 views
0

에 대한 실패, 기본에 PackageName 앱을 준비하기위한에 PackageName 있도록 applicationIdSuffix를 추가 com.kagarlickij.myapplication안드로이드 ExampleInstrumentedTest 내가 테스트 안드로이드 응용 프로그램에서 일하고 있어요 맛

내 '개발'과 '준비'productFlavors 것은 com.kagarlickij.myapplication.**staging**

경우 I

> 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 

기본 ExampleInstrumentedTest.java : ./gradlew connectedStagingDebugAndroidTest를 실행 나는이 예외를 받고 있어요

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://d.android.com/tools/testing">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 - https://github.com/kagarlickij/MyApplication/blob/dev/0.4.0/app/build.gradle

어떻게 ExampleInstrumentedTest.java는 맛에서 PackageNames을 지원하기 위해 변경 될 수 있습니다 ?

+0

공유 Gradle을 파일 – Omi

+0

@Omi는, 그것의 https://github.com/kagarlickij/MyApplication /blob/dev/0.4.0/app/build.gradle – kagarlickij

+0

제거 ** testImplementation ** 그레고리 파일에서 3 줄을 청소하고 다시 작성하십시오. – Omi

답변

1

에 한번 테스트에 맛 이름을 추가, 뭔가 같은 :

assertEquals("com.kagarlickij.myapplication." + BuildConfig.FLAVOR , appContext.getPackageName()); 

OR :

assertEquals(BuildConfig.APPLICATION_ID, appContext.getPackageName()); 
+0

둘 다 노력하고 있습니다. 많은 도움을 주셔서 감사합니다! – kagarlickij