【问题标题】:JUnit 4 with ActivityInstrumentationTestCase2带有 ActivityInstrumentationTestCase2 的 JUnit 4
【发布时间】:2015-01-21 14:52:54
【问题描述】:

我可以将 JUnit 4 与我的类扩展 ActivityInstrumentationTestCase2 一起使用吗?

我收到以下警告:

@Test 在扩展 JUnit3 TestCase 的类中

我的班级

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
}

【问题讨论】:

    标签: android junit4 android-testing junit3


    【解决方案1】:

    我可以将 JUnit 4 与我的类扩展 ActivityInstrumentationTestCase2 一起使用吗?

    是的,但您必须遵循 the documented recipe(请参阅页面下方的 ActivityInstrumentationTestCase2 说明)。

    This sample project 包含一个遵循配方的ActivityInstrumentationTestCase2

    我收到以下警告

    是的,那是an IDEA warning that should be fixed in an upcoming release of Android Studio

    【讨论】:

      【解决方案2】:

      不。 Android JUnit 是 JUnit3。测试是名称以“test”开头的方法

      【讨论】:

      • AndroidJUnitRunner 提供对 JUnit4 的支持,并提供了使 ActivityInstrumentationTestCase2 工作的具体说明。这有点笨拙,会触发问题中提到的 IDEA 警告,但它有效。
      • 我会被诅咒的!投票给自己。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 2011-04-19
      • 2016-09-05
      • 1970-01-01
      • 2020-11-19
      相关资源
      最近更新 更多