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()
}