【问题标题】:ActivityTestRule is deprecated on android testActivityTestRule 在 android 测试中被弃用
【发布时间】:2021-10-18 13:09:42
【问题描述】:

这是我的仪器测试的范围:

...
import androidx.test.rule.ActivityTestRule

@RunWith(AndroidJUnit4::class)
@LargeTest
class InstrumentDialogFragmentTest {

    @get:Rule
    val activityRule = ActivityTestRule(MainActivity::class.java)
}

我的毕业生:

androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:rules:1.4.0'

我收到此警告:

'ActivityTestRule<T : Activity!>' is deprecated. Deprecated in Java

【问题讨论】:

  • 我遇到了同样的问题。在developers.android 链接中它指出:此类已弃用。请改用 ActivityScenario 或 ActivityScenarioRule。它们提供了一种更简单、更安全的控制 Activity 生命周期的方法。然后有一些转换提示。抱歉,我没有时间尝试转换,所以我不知道转换的参与程度。

标签: android automated-tests junit4 android-instrumentation deprecation-warning


【解决方案1】:

您仍然可以在“androidx.test:rules:1.2.0”上使用它。 它在 1.4.0 上已弃用。 请改用 ActivityScenario 或 ActivityScenarioRule。

查看更多:enter link description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 2018-11-07
    • 2023-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多