2017-06-15 13 views
0

android私は2つのアクティビティ、MainActivityとDetailsActivityを持つサンプルアプリケーションを持っています。メインアクティビティにはリストとボタンがあり、それを押すと詳細アクティビティが開きます。その意図で、ArrayListとObjectを配置します。ボタンをクリックするとアクティビティが表示されることをどのようにテストできますか?

どのように動作するかテストできますか?エスプレッソそれは大丈夫ですか?

androidTestCompile 'com.android.support:support-annotations:25.3.1' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 



@RunWith(AndroidJUnit4.class) 
@LargeTest 
public class FirstTest { 
    @Rule 
    public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(
      MainActivity.class); 

    @Test 
    public void changeText_sameActivity() { 

     onView(withId(R.id.fab)).perform(click()); 
     // How can i Specify the intent to the new Detail Activity? 
    intended(hasComponent(new ComponentName(getTargetContext(), InsectDetailsActivity.class))); 


     onView(withId(R.id.tv_original_title)) 
       .check(matches(withText(/* The text depends on the Passing Intent*/))); 

    } 
} 

答えて

1

重複した質問。 hereを参照してください。その質問からの回答は次のとおりです。

intended(hasComponent(new ComponentName(getTargetContext(),ExpectedActivity.class))) 
+0

私はいくつかの編集を行います。 1つのインテントにマッチするWantedが見つかりました。実際に一致した0のインテント。そして、私はどのようにしてExtrasをすべての目的に合格させることができますか?私はArrayListとObjectを作成して新しく作成したActivityにそれらを渡すべきですか(ありがとう) –

+0

あなたは意図した意図を使わなければなりません。また、さまざまなアクティビティに関連するアサーションには、異なるテストケースを使用する必要があります。 –

関連する問題