不是由Android工作室发现TestCase类 [英] TestCase class not found by Android Studio

查看:153
本文介绍了不是由Android工作室发现TestCase类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的测试案例类并把它放在默认的测试目录为Android工作室:SRC / androidTest。我创建了一个Android测试生成配置,看起来为模块中的所有测试。当我运行生成的配置,我的测试并没有执行,我得到的logcat以下消息: W / TestGrouping:无效的包:'无法找到或没有测试。如果我指定的测试包,甚至具体的测试类,我得到类似的类未找到的消息。

I have written a simple test case class and placed it in the default test directory for Android Studio: "src/androidTest". I've created an Android Tests build configuration that looks for all Tests in the module. When I run the build configuration, my test does not execute and I get the following message in logcat: W/TestGrouping﹕ Invalid Package: '' could not be found or has no tests. If I specify the test package or even the specific test class, I get similar class not found messages.

我的测试类如下:

public class FirstTest extends InstrumentationTestCase {

public void testSample() {
        final int expected = 1;
        final int reality = 5;
        assertEquals(expected, reality);
    }
}

我的build.gradle文件看起来像这样:

My build.gradle file looks like this:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:gridlayout-v7:19.0.1'
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

我跑了Android插件的Gradle 0.9版本。我顶层的build.gradle(同行到应用程序目录中)看起来是这样的。

I'm running version 0.9 of the android gradle plugin. My top level build.gradle (a peer to the app directory) looks like this.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

我的项目的目录结构如下:

My project directory structure is as follows:

应用
    SRC
        androidTest
            java的
        主要
            java的
            RES

推荐答案

在androidTest / java目录下的包结构需要完全平行的主/ java目录下的结构。

The package structure under the androidTest/java directory needs to exactly parallel the structure under the main/java directory.

以上我的问题是,在主要的包装结构 com.mydomain.myapp.subpackage 和androidTest下的目录结构为 com.mydomain .myapp.subpackage.somethingelse

My problem above was that the package structure under main was com.mydomain.myapp.subpackage and the directory structure under androidTest was com.mydomain.myapp.subpackage.somethingelse.

一旦封装结构匹配,测试发现并完美地执行。

Once the package structures matched, the tests were discovered and executed flawlessly.

这篇关于不是由Android工作室发现TestCase类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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