我想在我的

Android应用程序项目中运行简单,简单的JUnit测试,同时使用Gradle编写Activity测试.花了很长时间配置Gradle并使其工作,但是,无论如何,现在我仍然试图让JUnit测试只是编译.

我检查了这个link,但是当我运行gradle时,我收到以下错误:

DummyTest.java:3: error: package junit.

framework does not exist

import junit.framework.Assert;

^

\DummyTest.java:8: error: cannot find symbol

Assert.assertEquals(5,3);

^

symbol: variable Assert

location: class DummyTest

所以,找不到junit ……

以下是我的完整gradle.build文件:

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath 'com.android.tools.build:gradle:0.6.+'

}

}

apply plugin: 'android'

repositories {

mavenCentral()

}

dependencies {

compile files('libs/joda-time-2.3.jar')

compile files('libs/android-support-v4.jar')

unitTestCompile files("$project.buildDir/classes/release")

unitTestCompile 'junit:junit:4.8.2'

}

android {

compileSdkVersion 17

buildToolsVersion '17.0.0'

sourceSets {

main {

manifest.srcFile 'AndroidManifest.xml'

java.srcDirs = ['src']

resources.srcDirs = ['src']

aidl.srcDirs = ['src']

renderscript.srcDirs = ['src']

res.srcDirs = ['res']

}

unitTest {

java.srcDir file('test')

resources.srcDir file('test/res')

}

}

defaultConfig {

minSdkVersion 14

versionName '1.0'

versionCode 1

targetSdkVersion 17

}

}

// add the unitTest task

task unitTest(type:Test, dependsOn: assemble) {

description = "run unit tests"

testClassesDir = project.sourceSets.unitTest.output.classesDir

classpath = project.sourceSets.unitTest.runtimeClasspath

}

build.dependsOn unitTest

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐