ActivityTestRule 已被弃用,它是我正在学习的教程中使用的工具。
@RunWith(AndroidJUnit4::class)
@get:Rule
val activityRule = ActivityTestRule(MovieSpotterTestApp::class.java, true, false)
private val mockWebServer = MockWebServer()
@Before
fun setup() {
mockWebServer.start(8080)
IdlingRegistry.getInstance().register(
ServiceBuilder.getClient()?.let {
OkHttp3IdlingResource.create(
"okhttp",
it
)
}
)
}
@Test
fun testSuccessfulResponse() {
mockWebServer.dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse {
return MockResponse()
.setResponseCode(200)
.setBody(readStringFromFile("success_response.json"))
}
}
activityRule.launchActivity(null)
文档说我应该可以直接将其更改为,ActivityScenario.launch(Class)
但是我调用的activityRule.launchActivity(null)
行将无法运行。
我将如何更新这个?