大佬教程收集整理的这篇文章主要介绍了android – 构建本地单元测试(没有注册仪器!必须在注册仪器下运行),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所有尝试都是在一个新项目上进行的. Android studio 3.3,gradle-4.10.1,build:gradle:3.3.0,Kotlin,并包含Androidx工件.
的build.gradle
android { // ... testOptions { unitTests.includeAndroidresources = true } } dependencies { // ... // Already exist testImplementation 'junit:junit:4.12' // Added this line testImplementation 'androidx.test:core:1.0.0' }
而测试体本身:
package com.example.myapplication import android.content.Context import androidx.test.core.app.ApplicationProvider import org.junit.Test class ExampleUnitTest { val context = ApplicationProvider.getApplicationContext<Context>() @Test fun readStringFromContext_LocalizedString() { System.out.println(context.applicationInfo.packageName) } }
我究竟做错了什么?
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 28 defaultConfig { applicationId "com.example.myapplication" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testinstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro' } } testOptions { unitTests.includeAndroidresources = true } } dependencies { implementation fileTree(dir: 'libs',include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.0-beta01' implementation 'androidx.core:core-ktx:1.1.0-alpha03' implementation 'androidx.consTraintlayout:consTraintlayout:1.1.2' testImplementation 'junit:junit:4.12' testImplementation 'androidx.test:core:1.0.0' androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' }
以上是大佬教程为你收集整理的android – 构建本地单元测试(没有注册仪器!必须在注册仪器下运行)全部内容,希望文章能够帮你解决android – 构建本地单元测试(没有注册仪器!必须在注册仪器下运行)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。