Gradle和Android以及Robolectric - 清空测试类路径

时间:2014-03-09 23:21:14

标签: robolectric android-gradle

我正在将我的项目迁移到Gradle,我有一个单独的工作Robolectric设置以及我的应用程序。

Robolectric测试位于test/文件夹下,它们应该在运行时包含应用程序jar文件(感谢another SO问题)和其他依赖项。

测试由Gradle启动,但类路径看起来是空的。

gradle.build:

apply plugin: 'java'

test {
   // The classpath.each prints:
   // /test-robolectric/build/classes/test
   // /test-robolectric/build/resources/test
   // /test-robolectric/build/classes/main
   // /test-robolectric/build/resources/main

    classpath.each { file ->
        println file.absolutePath
    }     

    reports {
        html.enabled = true
    }

    // show standard out and standard error of the test JVM(s) on the console
    testLogging.showStandardStreams = false

    // listen to events in the test execution lifecycle
    beforeTest { descriptor ->
        logger.lifecycle("Running test: " + descriptor)
    }
}

dependencies {
    compile project(':test-common:test-common-jar')
    compile project(path: ':app', configuration: 'testJar')
    compile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    compile 'com.google.android:android:4.+'
    compile 'com.android.support:appcompat-v7:19+@jar'
    compile 'com.android.support:support-v4:19.+'
    compile 'com.google.inject:guice:4.0-beta:no_aop'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.functionaljava:functionaljava:3.1'
    compile 'javax.inject:javax.inject:1@jar'
    compile 'com.squareup:otto:1.3.4@jar'
    compile 'net.jcip:jcip-annotations:1.0'
    compile 'de.akquinet.android.androlog:androlog:1.0.5'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'junit:junit:4.11'
    compile 'org.mockito:mockito-all:1.9.+'
    compile 'org.hamcrest:hamcrest-core:1.+'
    compile 'com.squareup:fest-android:1.0.+'
}

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url 'http://repository.grepcode.com/java/ext'
    }
}

我还尝试将dependecies声明放在test{}部分内无济于事。我在这里缺少什么?

具体例外:

java.lang.NoClassDefFoundError: android/content/Context
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
    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 org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
[...]

0 个答案:

没有答案