2017-12-02 9 views
0

저는 Espresso를 처음 사용하여 UI 단위 테스트를 시도했습니다. 나는 많은 연구를 위해 해왔 던 문제에 직면했다. 나는 그것을 해결하는 방법을 알지 못한다. 단지 간단한 텍스트 입력과 버튼 클릭만으로 누군가가 나를 도와 주길 바란다.Android Espresso UI 테스트 ---- 테스트 실행 실패 : '프로세스 충돌'로 인해 계측 실행에 실패했습니다.

문제는 :

텍스트가 "HELLO"를 입력 한 다음 응용 프로그램은 다음과 같이 오류 로그로 추락 :

at dalvik.system.VMStack.getThreadStackTrace(Native Method) 
at java.lang.Thread.getStackTrace(Thread.java:595) 
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:92) 
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) 
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) 
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115) 
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87) 
at com.hongfans.rearview.MainActivityEspressoTest.testEnsureTextChangesWork(MainActivityEspressoTest.java:36) 
at java.lang.reflect.Method.invoke(Native Method) 
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 android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) 
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270) 
at org.junit.rules.RunRules.evaluate(RunRules.java:20) 
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:1904) 

Test running failed: Instrumentation run failed due to 'Process crashed.' 

내 테스트 코드 :

package **.**.**;//you know, this is hiding 

import android.provider.Settings; 
import android.support.test.filters.LargeTest; 
import android.support.test.rule.ActivityTestRule; 
import android.support.test.runner.AndroidJUnit4; 
import org.junit.Rule; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.junit.After; 
import static android.support.test.espresso.Espresso.onView; 
import static android.support.test.espresso.action.ViewActions.click; 
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; 
import static android.support.test.espresso.action.ViewActions.typeText; 
import static android.support.test.espresso.matcher.ViewMatchers.withId; 


@LargeTest 
@RunWith(AndroidJUnit4.class) 
public class MainActivityEspressoTest { 

// Rule this means which activity to run 
@Rule 
public ActivityTestRule<MainActivity> mActivityRule = 
     new ActivityTestRule<>(MainActivity.class); 
// Test means below is a test case 
@Test 
public void testEnsureTextChangesWork() { 
    //  // Type text and then press the button. 
    onView(withId(R.id.et_search)).perform(typeText("HELLO"), closeSoftKeyboard()); 
    onView(withId(R.id.bt_search)).perform(click()); 
    } 
} 

My Gradle config :

defaultConfig { 
     *** others *** 
     testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' 
     } 
androidTestCompile 'com.android.support:support-annotations:24.1.0' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2',{ 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource' 
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2' 
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2' 
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2'){ 
     exclude group: 'com.android.support', module: 'appcompat-v7' 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude module: 'recyclerview-v7' 
    } 

기타 정보 :

안드로이드 스튜디오 혼란 스럽다 : 2.3.3 내 AS 디렉토리는 다음과 같습니다 java.lang.RuntimeException가 : enter image description here

답변

0

로그에 대한 연구를 수행 한 후, 나는 예외가 있음을 발견 : 내 설정이 맞다,라고하는 것입니다 android.support.test.espresso.AmbiguousViewMatcherException

는 유일한 문제는 발견 된 동일한 ID를 가진 두 요소가있다, 그래서 ... 그냥 지시를 따르 https://developer.android.com/training/testing/espresso/basics.html#components 다음 : https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html 문제가 해결되었습니다.