2017-01-06 16 views
0

私はコマンドラインからアプリケーションをテストしようとしています。 Android Studioからテストを実行すると、すべてうまく行きます。私は、コマンドを実行しようとする。しかし:実行方法./gradlewテスト

./gradlew test 

私はこのエラーを取得する:

Task 'test' not found in root project 'mvp_kotlin_example'. 

私は./gradlewビルドまたは./gradlewクリーンを使用して問題はありません。私は./gradlewテストを試すプロジェクトを作成しました。

mvp_kotlin_exampleでは、テスト用にRobolectricを使用し、開発用にKotlinを使用しています。

どうすればテストをコマンドラインから実行できますか?

編集:

これは、オープンソースプロジェクトであるため、すべてのコードが

https://github.com/leandroBorgesFerreira/mvp-kotlin-example

で見つけることができますこれは私のbuild.gradleファイルです:

apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-android-extensions' 
apply from: '../jacoco.gradle' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     applicationId "br.com.simplepass.simplepassnew" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
     debug { 
      testCoverageEnabled = true 
     } 
    } 
    sourceSets { 
     main.java.srcDirs += 'src/main/kotlin' 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    testCompile "org.robolectric:robolectric:3.1.4" 
    testCompile 'com.squareup.okhttp3:mockwebserver:3.3.1' 
    testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1' 
    testCompile "org.mockito:mockito-core:2.4.2" 
    compile 'com.android.support:appcompat-v7:25.1.0' 
    compile 'com.android.support:design:25.1.0' 
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 
    compile 'br.com.simplepass:loading-button-android:1.5.0' 
    compile 'org.jetbrains.anko:anko-sdk15:0.9' // sdk19, sdk21, sdk23 are also available 
    compile 'io.reactivex:rxandroid:1.2.1' 
    compile 'io.reactivex:rxjava:1.1.6' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' 
    compile 'com.google.dagger:dagger:2.8' 
    kapt 'com.google.dagger:dagger-compiler:2.8' 
    provided 'org.glassfish:javax.annotation:10.0-b28' 
} 
repositories { 
    mavenCentral() 
} 

kapt { 
    generateStubs = true 
} 

編集2:

これは私がここで

------------------------------------------------------------ 
All tasks runnable from root project 
------------------------------------------------------------ 

Build Setup tasks 
----------------- 
init - Initializes a new Gradle build. [incubating] 
wrapper - Generates Gradle wrapper files. [incubating] 

Help tasks 
---------- 
buildEnvironment - Displays all buildscript dependencies declared in root project 'mvp_kotlin_example'. 
components - Displays the components produced by root project 'mvp_kotlin_example'. [incubating] 
dependencies - Displays all dependencies declared in root project 'mvp_kotlin_example'. 
dependencyInsight - Displays the insight into a specific dependency in root project 'mvp_kotlin_example'. 
help - Displays a help message. 
model - Displays the configuration model of root project 'mvp_kotlin_example'. [incubating] 
projects - Displays the sub-projects of root project 'mvp_kotlin_example'. 
properties - Displays the properties of root project 'mvp_kotlin_example'. 
tasks - Displays the tasks runnable from root project 'mvp_kotlin_example'. 

Other tasks 
----------- 
clean 
+0

'build.gradle'ファイルを表示してください。 – Divers

+0

あなたはandroidTest(従来の単体テストとは対照的)を持っているようです。そのため、コマンドは './gradlew connectedAndroidTest'(または短い形式の' ./gradlew cAT'を使用できます) – Budius

+0

Budius、androidTestを使用していません。すべての私のテストは/ java/[mypackage]というテストの中にあり、私は従来の単体テストを使用しようとしています。それはAndroidスタジオで動作します –

答えて

3

問題は、あなたがbuild.gradleプロジェクトがGradleの伝えsettings.gradleファイルが欠落していたとは何の関係もありません(それはusuallよりもはるかに少ない作業をだ)./gradlewタスクを実行した後に見たものですappフォルダをモジュールとして含めることができます。私はこの欠陥を解決するためにあなたのプロジェクトにPR#1を作成しました。併合すると、./gradlew clean testをルートプロジェクトディレクトリから実行できるはずです。

https://github.com/leandroBorgesFerreira/mvp-kotlin-example/pull/1

ソリューションは、単にビルドに含まれるモジュールを宣言したルートプロジェクトにとしてoneline settings.gradleファイルを追加することです。

$ cat settings.gradle 
include 'app' 
+1

それは働いた。ありがとう! –

関連する問題