【问题标题】:android studio: how to change from junit 3 to junit 4android studio:如何从junit 3更改为junit 4
【发布时间】:2016-05-28 00:25:54
【问题描述】:

我的 android studio 正在运行 JUnit 3。如何将其更改为 JUnit 4? 我相信我的 gradle 文件是正确的。

android {
  …
  defaultConfig {
    …
    testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
  }
  …
}

dependencies {
    // Required -- JUnit 4 framework
    testCompile 'junit:junit:4.12'
    // Optional -- Mockito framework
    testCompile 'org.mockito:mockito-core:1.10.19'

    androidTestCompile 'com.android.support:support-annotations:23.2.0'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    // Optional -- Hamcrest library
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    // Optional -- UI testing with Espresso
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // Optional -- UI testing with UI Automator
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
}

我正在使用 Android Studio 2.1.1

更新

实际上,我使用的是 JUnit 4,但无论出于何种原因,我都必须在我的测试用例前面加上 test,就像在 testSomeMethodForX 中一样,而不是简单的 someMethodForX。我认为在 JUnit 4 中,不再需要这个前缀?

【问题讨论】:

  • 你能分享你的测试代码吗?

标签: android android-studio gradle junit


【解决方案1】:

如果您的类仍然扩展 TestCase(或另一个本身扩展 TestCase 的类),那么 JUnit 4 会运行 JUnit 3 测试,因此您必须在它们前面加上 test。不要再扩展TestCase,如果存在@Test 注解,它们就会运行。

【讨论】:

  • 我的课程没有扩展TestCase
猜你喜欢
  • 1970-01-01
  • 2011-04-19
  • 2012-03-05
  • 1970-01-01
  • 2011-10-23
  • 1970-01-01
  • 1970-01-01
  • 2013-11-04
  • 2011-10-04
相关资源
最近更新 更多