我正在尝试使用Jenkins和Gradle构建一个Android项目。在compileUnitTestJava任务中构建失败,没有找到测试中导入的任何类。在Android Studio中,运行测试没有问题,但在Jenkins上,构建失败。
项目中包含的测试如下:
package mobile_teacher.test;
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import mobile_teacher.R;
import mobile_teacher.src.DashboardActivity;
/**
* Created by blavi on 6/2/14.
*/
public class DashboardTest extends ActivityUnitTestCase<DashboardActivity> {
public DashboardActivity activity;
public DashboardTest() {
super(DashboardActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
Intent intent = new Intent(getInstrumentation().getTargetContext(),
DashboardActivity.class);
startActivity(intent, null, null);
activity = getActivity();
}
public void testLayout(){
assertNotNull(activity.findViewById(R.id.lessonsList));
}
}
build.gradle是:
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['src/main/res']
}
}
lintOptions {
abortOnError false
}
}
// extend the runtime
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
compile files('libs/libGoogleAnalyticsServices.jar')
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.google.android.gms:play-services:4.3.23'
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.11'
unitTestCompile 'com.google.android:android:4.0.1.2'
unitTestCompile 'com.google.android:android-test:4.1.1.4'
}
// add a new unitTest sourceSet
sourceSets {
unitTest {
java.srcDir file('src/tests/java')
}
}
// 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
}
check.dependsOn unitTest