5

私はJake Wharton の素晴らしいプラグインを Android 単体テストに使用しています。これらの単体テストを実行するために苦労した私の目的は、スピード (TDD クイック フィードバックとすべて) のためです。

私はそれを正しく構成することができ、次のようにいくつかのサンプルテストを実行しています:

./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

Gradle は私のプロジェクトのすべての依存関係を読み込んでいるようです。

私のサンプルテストは次のとおりです。

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);
  }
}

このテストの実行には、実際には数分の 1 秒かかります。私の理解では、プロジェクトの依存関係を事前にロードすることはすべて、それを行き詰まらせているということです。

良い日には、必要なものが CLASSPATH にあることを確認し、次のように実行します。

javac src/test/java/main/java/com/micromobs/pkk/AdditionOperationsTest.java
java org.junit.runner.JUnitCore com.micromobs.pkk.AdditionOperationsTest

これが gradle を使用した Android プロジェクトであることを考えると、サンプル プロジェクトのテスト ファイルのみを含む特定のタスクを gradle ビルド ファイルに作成し、gradle コマンドを実行するなど、少し異なることを行う必要があると思います。 /gradlew タスク名 ?

質問: 外部プロジェクトの依存関係を読み込まないように、プロジェクト (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
4

1 に答える 1

4

-a コマンド ライン オプション(プロジェクトの依存関係の再構築なし)を使用して、これを行うことができます。を実行gradle -a testすると、libraries:facebookおよびmysampleappプロジェクトが再構築されません。

編集:以下に示すように、 Gradle デーモンを使用すると、Gradle ビルドのパフォーマンスを大幅に向上させることができます。

于 2013-10-10T21:38:01.393 に答える