【发布时间】: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