我使用awesome plugin from Jake Wharton Android的單元測試。爲了讓這些單元測試正常運行,我的目標是速度(TDD快速反饋和全部)。運行的gradle從單一的Android(單元)測試,而無需加載其他項目的依賴
我設法正確配置,並在運行一些樣本測試如下:
./gradlew test
每當我進行的測試,雖然我注意到下面的輸出:
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
The Test.testReportDir property has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the Test.getReports().getHtml().getDestination() property instead.
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
:mySampleApp:preBuild UP-TO-DATE
:mySampleApp:preDebugBuild UP-TO-DATE
:mySampleApp:preReleaseBuild UP-TO-DATE
:libraries:facebook:compileLint
:libraries:facebook:copyReleaseLint UP-TO-DATE
:libraries:facebook:mergeReleaseProguardFiles UP-TO-DATE
:libraries:facebook:packageReleaseAidl UP-TO-DATE
:libraries:facebook:preBuild UP-TO-DATE
:libraries:facebook:preReleaseBuild UP-TO-DATE
:libraries:facebook:prepareReleaseDependencies
:libraries:facebook:compileReleaseAidl UP-TO-DATE
:libraries:facebook:compileReleaseRenderscript UP-TO-DATE
:libraries:facebook:generateReleaseBuildConfig UP-TO-DATE
:libraries:facebook:mergeReleaseAssets UP-TO-DATE
:libraries:facebook:mergeReleaseResources UP-TO-DATE
:libraries:facebook:processReleaseManifest UP-TO-DATE
:libraries:facebook:processReleaseResources UP-TO-DATE
:libraries:facebook:generateReleaseSources UP-TO-DATE
:libraries:facebook:compileRelease UP-TO-DATE
:libraries:facebook:processReleaseJavaRes UP-TO-DATE
:libraries:facebook:packageReleaseJar UP-TO-DATE
:libraries:facebook:packageReleaseLocalJar UP-TO-DATE
:libraries:facebook:packageReleaseRenderscript UP-TO-DATE
:libraries:facebook:packageReleaseResources UP-TO-DATE
:libraries:facebook:bundleRelease UP-TO-DATE
:mySampleApp:prepareComAndroidSupportAppcompatV71800Library UP-TO-DATE
:mySampleApp:preparemySampleAppandroidLibrariesFacebookUnspecifiedLibrary UP-TO-DATE
:mySampleApp:prepareDebugDependencies
:mySampleApp:compileDebugAidl UP-TO-DATE
:mySampleApp:compileDebugRenderscript UP-TO-DATE
:mySampleApp:generateDebugBuildConfig UP-TO-DATE
:mySampleApp:mergeDebugAssets UP-TO-DATE
:mySampleApp:mergeDebugResources UP-TO-DATE
:mySampleApp:processDebugManifest UP-TO-DATE
:mySampleApp:processDebugResources UP-TO-DATE
:mySampleApp:generateDebugSources UP-TO-DATE
搖籃似乎加載我的項目的所有依賴關係。
我的樣品測試如下:
package com.mycompany.mysampleapp;
import org.junit.Test;
import static org.fest.assertions.api.Assertions.assertThat;
public class AdditionOperationsTest {
@Test public void testModulus() {
assertThat(1).isEqualTo(1);
}
}
這個測試實際上應該採取幾分之一秒到運行。我的理解是,所有預加載項目依賴關係都讓它陷入困境。
在美好的日子,我會確保我有什麼,我需要在CLASSPATH中,只是運行是這樣的:
javac src/test/java/main/java/com/micromobs/pkk/AdditionOperationsTest.java
java org.junit.runner.JUnitCore com.micromobs.pkk.AdditionOperationsTest
考慮到這是一個Android項目,gradle這個,我假設我將有做一些有點不同的事情,比如在Gradle構建文件中創建特定任務,其中只包含我的示例項目的測試文件,然後運行gradle命令./gradlew taskName?
問:是否可以運行我的項目(com.mycompany.mysampleapp)範圍內的單個測試「AdditionOperationsTest」獨所以它不會加載外部項目依賴
下面是我的配置文件目前看起來像:
# settings.gradle
include ':libraries:gradle-android-test-plugin'
include ':libraries:facebook', ':mysampleapp'
# build.gradle
...
apply plugin: 'android-test'
dependencies {
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.1.+'
testCompile 'com.squareup:fest-android:1.0.+'
}
# location of my test files:
androidproj/mysampleapp/src/test/java/main/com/mycompany/mysampleapp/AdditionOperationsTest.java
我試圖解決這個同樣的問題。我認爲要做的事情就是擁有多模塊項目,以便測試存在於一個單獨的模塊中,但我希望這不是必需的。 – Turnsole
是的,我真的不想把我的測試分解成不同的模塊。我覺得我會失去將我們整個項目轉移到gradle的好處。我希望這只是我必須添加的一些愚蠢的參數或者我必須聲明的任務,它會忽略外部項目依賴關係,並運行我指向的確切測試以及它只需要的依賴關係。 –