使用AndroidX运行检测测试时未找到测试 [英] No tests found when running instrumented tests with AndroidX

查看:511
本文介绍了使用AndroidX运行检测测试时未找到测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Android项目(使用AndroidX)中​​运行标准的ExampleInstrumentedTest,但是却收到未找到测试"错误.我仔细阅读了其他问题和文档,很确定我做对了所有事情,但是也许我忽略了什么?

I'm trying to run the standard ExampleInstrumentedTest in my Android project (which uses AndroidX), but get "No tests found" error instead. I've looked through the other questions and the documentation and I'm pretty sure I've done everything right, but maybe I'm overlooking anything?

这是我的应用程序的build.gradle:

Here is my app's build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit4"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Gradle automatically adds 'android.test.runner' as a dependency.
    useLibrary 'android.test.runner'

    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
}

repositories {
    mavenCentral()
    maven {
        url("https://oss.sonatype.org/content/repositories/snapshots")
    }
    maven { url 'https://jitpack.io' }
}


dependencies {
    // Core library
    androidTestImplementation 'androidx.test:core:1.0.0'

    // AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'

    // Assertions
    androidTestImplementation 'androidx.test.ext:junit:1.0.0'
    androidTestImplementation 'androidx.test.ext:truth:1.0.0'
    androidTestImplementation 'com.google.truth:truth:0.42'

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

// More dependencies...    

和ExampleInstrumentedTest.java:

and ExampleInstrumentedTest.java:

import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        Context appContext = ApplicationProvider.getApplicationContext();
        assertEquals("XXX", appContext.getPackageName());
    }
}

运行代码时,出现未找到测试".

when I run the code, I get "No tests found".

推荐答案

我需要更换跑步机

"androidx.test.ext.junit.runners.AndroidJUnit4"

使用

"androidx.test.runner.AndroidJUnitRunner"

这篇关于使用AndroidX运行检测测试时未找到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆