在Android Studio进行“简单配置”单元测试(Android Junit)
生活随笔
收集整理的這篇文章主要介紹了
在Android Studio进行“简单配置”单元测试(Android Junit)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
后來(lái)今天突然自己又抽風(fēng)。又想去弄一下Android junit。
文檔是:https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
// Dependencies for local unit tests
testCompile 'junit:junit:' + rootProject.ext.junitVersion
testCompile 'org.mockito:mockito-all:' + rootProject.ext.mockitoVersion
testCompile 'org.hamcrest:hamcrest-all:' + rootProject.ext.hamcrestVersion
// Android Testing Support Library's runner and rules
androidTestCompile 'com.android.support.test:runner:' + rootProject.ext.runnerVersion
androidTestCompile 'com.android.support.test:rules:' + rootProject.ext.rulesVersion
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
sourceSets{
sourceSets{
main{
java.srcDirs = ['src']
}
androidTest{
java.srcDirs = ['androidTest/src']
}
test{
java.srcDirs = ['test/src']
}
}
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
System.out.println("123");
}
}
public class AndroidRuntimeCodeTest extends AndroidTestCase {
public void testHello() throws Exception {
System.out.println("testHello");
}
}
<manifest > <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.viewtest"?/>
</manifest>
<uses-library?android:name="android.test.runner"?/> </application>
android{ defaultConfig?{ testInstrumentationRunner?'android.support.test.runner.AndroidJUnitRunner' } }
引用:https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK configurations.all {
resolutionStrategy {
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
forcedModules = ['com.android.support:support-annotations:23.0.1']
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/shortboy/p/5634006.html
總結(jié)
以上是生活随笔為你收集整理的在Android Studio进行“简单配置”单元测试(Android Junit)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: json和对象、list互转
- 下一篇: Android音频开发(4):如何存储和