0

내가 템플릿 다음에 적응하려고 노력 실행할 수 없습니다 :Gradle을 + Robolectric + 에스프레소 : 별도

deckard-gradle 내가 안드로이드 스튜디오 0.8.14 (베타)를 사용합니다.

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 
apply plugin: 'robolectric' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "20.0.0" 

    defaultConfig { 
     applicationId "com.example.myapp" 
     minSdkVersion 18 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
    } 
    buildTypes { 
     release { 
      runProguard false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    sourceSets { 
     androidTest { 
      setRoot('src/test') 
     } 
    } 
    packagingOptions { 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'LICENSE.txt' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
    } 
} 

robolectric { 
    include '**/*Test.class' 
    exclude '**/espresso/**/*.class' 
} 

configurations { 
    apt 
} 

apt { 
    arguments { 
     resourcePackageName android.defaultConfig.packageName 
     androidManifestFile variant.outputs[0].processResources.manifestFile 
    } 
} 

ext { 
    daggerVersion = '1.2.2'; 
    androidAnnotationsVersion = '3.2'; 
    robobindingVersion = '0.8.9'; 
    jodatimeVersion = '2.5.1'; 
    ormliteVersion = '4.48'; 
    ottoVersion = '1.3.5'; 
    commonsioVersion = '2.0.1'; 
    playservicesVersion = '6.1.71'; 
    supportv4Version = '21.0.2'; 
    javaxinjectVersion = '1'; 
    junitVersion = '4.11'; 
    robolectricVersion = '2.4'; 
} 

dependencies { 
    // Espresso 
    androidTestCompile files('libs/espresso-1.1.jar', 'libs/testrunner-1.1.jar', 'libs/testrunner-runtime-1.1.jar') 
    androidTestCompile 'com.google.guava:guava:14.0.1' 
    androidTestCompile 'com.squareup.dagger:dagger:1.2.2' 
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.1' 
    androidTestCompile 'org.hamcrest:hamcrest-core:1.1' 
    androidTestCompile 'org.hamcrest:hamcrest-library:1.1' 

    androidTestCompile("junit:junit:${junitVersion}") { 
     exclude module: 'hamcrest-core' 
    } 

    androidTestCompile("org.robolectric:robolectric:${robolectricVersion}") { 
     exclude module: 'classworlds' 
     exclude module: 'commons-logging' 
     exclude module: 'httpclient' 
     exclude module: 'maven-artifact' 
     exclude module: 'maven-artifact-manager' 
     exclude module: 'maven-error-diagnostics' 
     exclude module: 'maven-model' 
     exclude module: 'maven-project' 
     exclude module: 'maven-settings' 
     exclude module: 'plexus-container-default' 
     exclude module: 'plexus-interpolation' 
     exclude module: 'plexus-utils' 
     exclude module: 'wagon-file' 
     exclude module: 'wagon-http-lightweight' 
     exclude module: 'wagon-provider-api' 
    } 

    androidTestCompile 'com.squareup:fest-android:1.0.+' 

    apt "org.robobinding:codegen:$robobindingVersion" 
    compile("org.robobinding:robobinding:$robobindingVersion:with-dependencies") { 
     exclude group: 'com.google.guava', module: 'guava' 
    } 
    apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}" 
    compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}" 
    apt "com.squareup.dagger:dagger-compiler:${daggerVersion}" 
    compile "com.squareup.dagger:dagger:${daggerVersion}" 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile "com.google.android.gms:play-services:${playservicesVersion}" 
    compile "com.android.support:support-v4:${supportv4Version}" 
    compile "com.squareup:otto:${ottoVersion}" 
    compile "javax.inject:javax.inject:${javaxinjectVersion}" 
    compile "com.j256.ormlite:ormlite-core:${ormliteVersion}" 
    compile "com.j256.ormlite:ormlite-android:${ormliteVersion}" 
    compile group: 'commons-io', name: 'commons-io', version: "${commonsioVersion}" 
    compile "net.danlew:android.joda:${jodatimeVersion}" 
} 

apply plugin: 'idea' 
idea { 
    module { 
     testOutputDir = file('build/test-classes/debug') 
    } 
} 

android.applicationVariants.all { variant -> 
    def aptOutput = file("${project.buildDir}/generated/source/apt/${variant.dirName}") 
    println "****************************" 
    println "variant: ${variant.name}" 
    println "manifest: ${variant.processResources.manifestFile}" 
    println "aptOutput: ${aptOutput}" 
    println "****************************" 

    variant.javaCompile.doFirst { 
     println "*** compile doFirst ${variant.name}" 
     aptOutput.mkdirs() 
     variant.javaCompile.options.compilerArgs += [ 
       '-processorpath', configurations.apt.getAsPath(), 
       '-AandroidManifestFile=' + variant.processResources.manifestFile, 
       '-s', aptOutput 
     ] 
    } 
} 

내가 단위 테스트를 실행하는 방법을 시도 :

이 내 build.gradle입니다

내가 gradlew 테스트를 사용하는 경우 내가 얻을 예외 때문에 (또한 계측) 모든 테스트 실행됩니다. 나는 JUnit 테스트를 실행하는 안드로이드 스튜디오 사용하는 경우

나는이 오류를 얻을 : 여러 가지 이유를 들어

!!! JUnit version 3.8 or later expected: 

java.lang.RuntimeException: Stub! 
    at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) 
    at junit.textui.TestRunner.<init>(TestRunner.java:54) 
    at junit.textui.TestRunner.<init>(TestRunner.java:48) 
    at junit.textui.TestRunner.<init>(TestRunner.java:41) 
    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:190) 
    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:173) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:56) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 

Process finished with exit code -3 
+0

https://github.com/robolectric/robolectric-gradle-plugin#importing-into-your-ide-intellij-or-android-studio에서 잘 알려진 오류입니다. 불행히도 Google은 Robolectric을 공식적으로 지원하지 않습니다. 손으로 수정 프로젝트 파일에 대한 단계를 수행 했습니까? –

+0

iml 파일을 편집 한 후에 프로젝트를 컴파일하지 못했습니다. 어쩌면 내가 실수 한거야. 하지만 내 패키지 이름에 오류가 있음을 알았습니다. 이 문제를 수정 한 후에 적어도 gradlew로 테스트를 수행 할 수있었습니다. 그게 충분 해. –

답변

0

을, 나는 내 Robolectric 테스트를 유지하는 대신 위의 접근 방식을 포기했습니다 Gradle submodule. 내가 왜이 방향으로 이사했는지에 대한 블로그 게시물과 deckard-gradle 프로젝트의 포크를 찾을 수 있습니다. here.