android运行测试注册,android – 构建本地单元测试(没有注册仪器!必须在注册仪器下运行)...

参见英文答案 >

AndroidX : No instrumentation registered! Must run under a registering instrumentation                                    2个

看一下官方的

documentation.Include framework dependencies一节给出了一个如何设置本地单元测试以使用android sdk环境的例子.但是,如果您按照示例执行所有操作,则测试无法启动.我得到了一个错误

java.lang.IllegalStateException: No instrumentation registered! Must

run under a registering instrumentation.

所有尝试都是在一个新项目上进行的. 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()

@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'

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值