让gradle这个执行JUnit测试(Android应用程序,Android的工作室) [英] getting gradle to execute JUnit Test (Android app, Android Studio)
问题描述
我目前工作的一个Android应用程序,并从最近的Eclipse切换到Android工作室(不是我的主意;))。不过,我想配置詹金斯服务器运行规律的基础上JUnit测试等测试。要做到这一点,我尝试配置gradle这个buidlfile。这里是我的设置:
I am currently working on an android app and lately switched from Eclipse to Android Studio (wasn't my idea;)). However I want to configure a jenkins server to run JUnit Tests and other tests on a regularly basis. To achieve this, I try to configure a gradle buidlfile. Here is my setup:
目录结构:
-app
-src
-main
-test
该文件的build.gradle(位于SRC /的build.gradle)
The build.gradle file: (located in "src/build.gradle)
apply plugin: 'android'
sourceSets {
unitTest {
java.srcDir file('src/test/java/[appName]/app')
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
instrumentTest.setRoot('src/test')
}
}
task unitTest(type:Test) {
testClassesDir = sourceSets.unitTest.output.classesDir
classpath = sourceSets.unitTest.runtimeClasspath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v13:+'
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
unitTest 'junit:junit:4.10'
}
TestClass中MainActivityTest.java
Testclass MainActivityTest.java
package [appName].app;
import android.test.InstrumentationTestCase;
import junit.framework.Assert;
public class MainActivityTest extends InstrumentationTestCase{
public void testMain(){
Assert.assertEquals(1,2);
}
}
和最重要的一块,该错误信息:
and the most important piece, the error message:
Error:(41, 0) Build script error, unsupported Gradle DSL method found: 'unitTest()'!
这是我第一次与gradle这个和Android Studio的工作,我也实在没有什么线索,我做错了。在互联网上,我只觉得人有类似问题,但没有人与为我工作的解决方案。我会很高兴,如果你能在正确的方向指向我!
It is my first time working with gradle and Android Studio and I have really no clue what I am doing wrong. On the internet I only find people with similar problems, but no one with a solution which worked for me. I'd be really glad if you could point me in the right direction!
问候
推荐答案
该错误消息说,有没有这样的属性单元测试。测试依赖性声明与instrumentTest(旧)或androidTest(新建)。
The error message tell that there is no such property unitTest. Test dependency are declared with instrumentTest (old) or androidTest (New).
Android SDK中已经自带有一个JUnit 3依赖性。所以只要删除该行
Android sdk comes already with a junit 3 dependency. So just remove that line
这篇关于让gradle这个执行JUnit测试(Android应用程序,Android的工作室)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!