本文介绍了仍然没有错误 Android Studio 说“没有找到测试"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的 MainActivity 编写检测测试.我按照here给出的答案.仍然 Android Studio 找不到任何测试.我在 androidTest 文件夹中有 ApplicationTest.java 类.以下是课程内容:

I am trying to write an instrumentation test for my MainActivity. I followed the answers given here. Still Android Studio cannot find any tests. I have the class ApplicationTest.java in the androidTest folder. Here's the contents of the class:

package com.example.monicamarcus.mymusicplayer

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.example.monicamarcus.mymusicplayer.MainActivity;

public class ApplicationTest extends ActivityInstrumentationTestCase2<MainActivity> {
    public ApplicationTest() {
        super(MainActivity.class);
    }

    public void testNextTrackButton() throws Exception {
        Activity activity = getActivity();

        Button nextButton = (Button) activity.findViewById(R.id.nextTrackBt);
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                nextButton.performClick();
                assertTrue(currentPosition < songList.size());
            }});
        activity.finish();
    }
}

这个测试类有什么问题?还是通过测试?我没有收到任何错误,只是没有找到任何要运行的测试.在我运行 ApplicationTest 后,输出以以下几行结束:

What is wrong with this test class? Or with the tests? I don't get any error, it just does not find any test to run. After I run the ApplicationTest the output ends with the following lines:

Running tests
Test running startedFinish
Empty test suite.

这是应用程序的 build.gradle 文件:

Here's the build.gradle file for the app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.monicamarcus.mymusicplayer"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testApplicationId "app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
    buildTypes {
        debug {
            minifyEnabled false
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

android {
    useLibrary 'org.apache.http.legacy'
}

android {

    sourceSets {

        androidTest {
            java.srcDirs = ['androidTest/java']
        }

    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    androidTestCompile 'junit:junit:4.12'
}

这是测试运行的输出:

Testing started at 1:56 PM ...
Target device: gt_i8190n-4790068ee9a750c6
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug.apk
Uploading file to: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Installing com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Success


Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
Uploading file to: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Installing app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Success


Running tests
Test running startedFinish
Empty test suite.

在我进行了一些更改后(如果有人感兴趣,我可以发布它们),运行仪器测试类的结果如下:运行测试.测试运行开始.测试运行失败:没有测试结果.空的测试套件."没有人有过此类测试的经验吗?

After I made some changes (I can publish them if anybody is interested) the result of running the instrumentation test class read as follows: "Running tests. Test running started. Test running failed: No test results. Empty test suite." Nobody has experience with these kind of tests?

推荐答案

build.gradle 中,testApplicationId 看起来很奇怪.我会删除它和 testInstrumentationRunner.默认值应该没问题.具体来说,如果您不指定 testApplicationId,它将通过将 ".test" 附加到您的 applicationId 来创建.

In build.gradle, testApplicationId looks very strange. I would remove this and testInstrumentationRunner. The default values should be fine. Specifically, if you do not specify testApplicationId, it will be created by appending ".test" to your applicationId.

这篇关于仍然没有错误 Android Studio 说“没有找到测试"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:17