2017-12-02 23 views
0

私はエスプレッソを初めて使ってUIユニットテストをしようとしています。私は多くの研究のためにやった問題に遭遇しました。私はまだそれを解決する方法を見つけることができません。それは単なるテキスト入力とボタンクリックです。Android Espresso UIテスト----テストの実行に失敗しました: 'Process crashed'のために計測が失敗しました。

問題:

テキストは "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' 
    } 

その他の情報:

のAndroidメーカーVerion:2.3.3と私のASディレクトリは次のとおりです。 java.lang.RuntimeException: enter image description here

答えて

0

ログの研究を行った後、私は例外があることが見つかりました:私の設定が正しい、と言うことです android.support.test.espresso.AmbiguousViewMatcherException

は、唯一の問題は発見された同じIDを持つ2つの要素があるので、...そこの指示に従います。 https://developer.android.com/training/testing/espresso/basics.html#components 以降: https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html 問題が解決しました。

関連する問題