Android:浓咖啡:点击其他活动的按钮后无法启动一个活动:想要匹配1个意图。实际匹配的0个意图

时间:2019-04-11 17:07:07

标签: android android-espresso

Android Studio 3.2。

Espresso的测试:

FragmentManager

但是我得到了错误:

开始运行测试

import android.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import android.graphics.Typeface
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.rule.ActivityTestRule
import androidx.test.platform.app.InstrumentationRegistry

@RunWith(AndroidJUnit4::class)
@SmallTest
class TradersActivityTest {   

    @Rule
    @JvmField
    var activityActivityTestRule = ActivityTestRule(TradersActivity::class.java)

    @Rule
    @JvmField
    var jsonViewActivity = ActivityTestRule(JsonViewActivity::class.java)

    @Test
    fun itemListviewJsonButtonClick() {
        onView(withId(R.id.tradersRecyclerView))
                .perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(CHECK_ITEM_LIST_POS));
        onView(withRecyclerView(R.id.tradersRecyclerView).atPositionOnView(CHECK_ITEM_LIST_POS, R.id.viewJsonButton))
                .perform(click())
        // check the activity has launched intent
        Intents.init()
        intended(hasComponent(JsonViewActivity::class.java.getName()))
        Intents.release()
    }

0 个答案:

没有答案