无法在Android Studio中运行单元测试

马特乌斯·齐泰利(Mateus Zitelli)

我现在试图让单元测试再次工作两天,每次尝试运行它们时,都会出现此错误:

Process finished with exit code 1
Class not found: "XXXXX.XXXXX.XXXXX.XXX"Empty test suite.

尝试同时运行测试类或仅运行方法时会发生这种情况。我尝试清理所有测试配置并重建项目。此外,我能够找到其他人遇到相同的问题,因此,提出的解决方案无法有效解决我的问题。

这是我的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.1'

    defaultConfig {
        applicationId "XXXXXXXXXX"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dataBinding {
        enabled = true
    }
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.4.0'
    }
}

apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'

ext {
    supportLibVersion = '25.1.0'  // variable that can be referenced to keep support libs consistent
    jomlVersion = '1.8.4'
}

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support:support-v4:${supportLibVersion}"
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar')
    {
        transitive = true;
    }
    compile project(':circular-slider')
    compile project(':gpuimage-plus')
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'net.protyposis.android.mediaplayer:mediaplayer:4.2.2-rc1'
    compile 'net.protyposis.android.mediaplayer:mediaplayer-dash:4.2.2-rc1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.writingminds:FFmpegAndroid:0.3.2'
    compile 'com.makeramen:roundedimageview:2.3.0'
    compile 'io.reactivex:rxjava:1.2.4'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'com.minimize.android:rxrecycler-adapter:1.2.2'
    compile "org.joml:joml:${jomlVersion}"
    provided 'org.glassfish:javax.annotation:10.0-b28'
    compile 'org.jetbrains:annotations-java5:15.0'
    compile 'com.annimon:stream:1.1.3'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.powermock:powermock-api-mockito:1.6.5'
    testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.5'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.5'
    testCompile 'org.powermock:powermock-module-junit5:1.6.5'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'com.android.support:multidex:1.0.1'
}

以及测试开始的课程:

@PrepareForTest({XXXXXX.class, XXXXXX.class, XXXXXX.class, XXXXXX.class})
@RunWith(PowerMockRunner.class)
public class VideoPlayerModelUnitTest {

谢谢!

更新资料

通过更改AndroidMaifest文件中的引用,我能够部分解决此问题。

因此,将引用从以下位置更改:

<activity android:name="com.myapp.MusicSelector.MusicSelectorActivity"/>

至:

<activity android:name=".MusicSelector.MusicSelectorActivity"/>

但是,我无法创建新测试,甚至无法重命名测试方法。例如,如果我从以下位置重命名:

@Test
public void testVideoListToTimedClips() throws Exception {

至:

@Test
public void testVideoListToTimedClips2() throws Exception {

我得到错误:

java.lang.Exception: No tests found matching Method testVideoListToTimedClips2(io.collect.collect.functional.VideoPlayerModelIntegrationTest) from org.junit.internal.requests.ClassRequest@15eb5ee5

更新2

尝试一下,似乎Android Studio保留了对旧版本测试的引用。

我将测试方法的名称从更改为testVideoListToTimedClipstestVideoListToTimedClips2得到了这样的测试类:

@PrepareForTest({VideoPlayerModel.class, MediaPlayer.class, Common.class})
@RunWith(PowerMockRunner.class)
public class testVideoPlayerModelIntegration {
    @Test
    public void testVideoListToTimedClips2() throws Exception {

当我运行测试类时,Android Studio运行旧方法:

在此处输入图片说明

强J2

您正在使用Android Studio 2.3.0-beta1吗?如果是这样,有一个错误会导致您在尝试运行单元测试时无法构建它们。

您可以通过先运行Make project然后Run每次运行单元测试来解决此问题

这个问题应该在下一个Android Studio的canary / beta版本中修复。

来源:https//code.google.com/p/android/issues/detail?id = 230688

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法运行单元测试用例

Android Studio单元测试中的Assets文件夹

无法在Spring Boot中运行任何单元测试

Xunit单元测试将无法运行

在Android Studio中运行所有单元测试

找不到类:在Android Studio中运行单元测试时,测试套件为空

在Android Studio中运行参数化单元测试时,找不到给定的测试包含错误

在Android Studio的“保存”上运行单元测试

无法在单元测试中运行远程功能

Django中单元测试的替代设置无法正常运行

Visual Studio 2017中的Xamarin(Android)单元测试

单元测试在运行时可以正常运行,但在Android Studio 4.1中调试时无法正常运行

单元测试配置在Android Studio 3.1中中断

dotnet核心:无法运行单元测试

angular-cli-单元测试无法在VSTS中运行?

无法在Visual Studio 2017 Professional中运行单元测试

在Android Kotlin中,assertNotNull导致单元测试无法运行

无法运行python单元测试

使用Mockito在Android中运行的单元测试

无法在Visual Studio Code中调试Django单元测试

无法在Webstorm中运行Typescript单元测试

Android中的单元测试?

在Android Studio中创建单元测试

JUnit Eclipse无法运行单元测试

无法在Visual Studio 2015中运行任何单元测试

Android Studio 中的单元测试出现错误

Android 中的单元测试

Flutter 在 Android Studio 中运行多个单元测试

Visual Studio 2019 - 无法运行 Python 单元测试 - 无法导入测试模块: