【发布时间】:2014-03-07 04:22:22
【问题描述】:
我编写了一个简单的测试用例类,并将其放在 Android Studio 的默认测试目录中:“src/androidTest”。我创建了一个 Android 测试构建配置,用于查找模块中的所有测试。当我运行构建配置时,我的测试没有执行,并且我在 logcat 中收到以下消息:W/TestGrouping﹕ Invalid Package: '' could not be found or has no tests。如果我指定测试包甚至特定的测试类,我会收到类似的类未找到消息。
我的测试类如下:
public class FirstTest extends InstrumentationTestCase {
public void testSample() {
final int expected = 1;
final int reality = 5;
assertEquals(expected, reality);
}
}
我的 build.gradle 文件如下所示:
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'])
}
我正在运行 0.9 版的 android gradle 插件。我的顶级 build.gradle(app 目录的对等)如下所示。
// 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()
}
}
我的项目目录结构如下:
app
src
androidTest
java
main
java
res
【问题讨论】:
-
包含您的项目目录结构以供测试。
标签: android android-studio automated-tests