0

Robolectrie テスト フレームワークを介して単体テストをビルドして実行しようとしていますが、使用している実際のプラグインが原因で実行できません

ここに私が試した私のビルドスクリプトがあります

//http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'http://www.testfairy.com/maven' }
    }

    dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.testfairy.plugins.gradle:testfairy:1.+'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'testfairy'
apply plugin: 'org.robolectric'


repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    testBuildType "debug"
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        testApplicationId "com.project.test"
//        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        //testInstrumentationRunner "com.project.test.Runner"
        manifestPlaceholders = [ adxUseQaServerEnabled: "ON" ]
    }

    testfairyConfig {
        apiKey "xxxx"
        metrics "cpu,memory,network,logcat"
        video "wifi"
        videoRate "0.5"
        videoQuality "low"
        maxDuration "10m"
        recordOnBackground true
        iconWatermark true
        testersGroups "projectName_Android"
        notify true
        maxDuration "1h"
        autoUpdate true
        uploadProguardMapping true
    }

    productFlavors {
        //testing {
        //}
        local {
        }
        mock {
        }
        qa {
        }
        //qa4 {
        //}
        production {
        }
    }

    sourceSets {
        local {
            res.srcDir 'build-config/local/res'
        }
        testing {
            res.srcDir 'build-config/testing/res'
        }
        mock {
            res.srcDir 'build-config/mock/res'
        }
        qa {
            res.srcDir 'build-config/qa/res'
        }
        qa4 {
            res.srcDir 'build-config/qa4/res'
        }
        staging {
            res.srcDir 'build-config/staging/res'
        }
        production {
            res.srcDir 'build-config/production/res'
        }
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-project.txt'
            signingConfig signingConfigs.release
            manifestPlaceholders = [ adxUseQaServerEnabled:"OFF" ]
        }
        debug {
            versionNameSuffix "-debug"
        }
    }
}

android.lintOptions {
    disable 'InvalidPackage'
    abortOnError false
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:support-v4:19.1.+'
    compile 'com.android.support:appcompat-v7:19.1.+'
    compile 'com.google.android.gms:play-services:5.0.+'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile "joda-time:joda-time:2.4"
    androidTestCompile ('junit:junit:4.12') {
        exclude module : 'hamcrest'
        exclude module : 'hamcrest-core'
    }
    androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile ('org.mockito:mockito-core:1.9.5') {
        exclude module : 'hamcrest'
        exclude module : 'hamcrest-core'
    }
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.sothree.slidinguppanel:library:3.0.0'

    compile 'com.jakewharton:butterknife:6.1.0'

    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-plugin-registry'
        exclude module: 'maven-profile'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'nekohtml'
        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-http-shared'
        exclude module: 'wagon-provider-api'
        exclude module: 'objenesis'
    }


}

ここに簡単なテストクラスがあります

/**
 * This class tests api calls
 */
@RunWith(RobolectricTestRunner.class)
public class ApiTestRobo {

    @Before
    protected void setUp() throws Exception {
        VolleyLog.DEBUG = true;
        ProjectApplication = (ProjectApplication) Robolectric.application;
        requestQueue = lmApplication.getRequestQueue();
        response = null;
    }

    @After
    protected void tearDown() throws Exception {
        requestQueue.cancelAll(new RequestQueue.RequestFilter() {
            @Override
            public boolean apply(Request<?> request) {
                return true;
            }
        });
        response = null;
    }

   @Test
    public void testGeocodeApi() {
        response = makeRequestSynchronous(RequestManager.geoCodeAddress("999 Bond High Road", new Response.Listener<GeocodeResponse>() {
            @Override
            public void onResponse(GeocodeResponse geocodeResponse) {

                response = geocodeResponse;
                notifyResponse();
            }
        }, errorListener));

        GeocodeResponse geocodeResponse = (GeocodeResponse) response;

        Assert.assertEquals("OK", geocodeResponse.status);
        Assert.assertEquals(51.4912901, geocodeResponse.results.get(0).geometry.location.lat);
        Assert.assertEquals(-0.2825666, geocodeResponse.results.get(0).geometry.location.lng);
    }

}

ここに私が得るエラーがあります

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':project'.
> Cannot invoke method systemProperty() on null object

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':project'.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:91)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:86)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:65)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.lang.NullPointerException: Cannot invoke method systemProperty() on null object
    at org.robolectric.gradle.RobolectricPlugin$_apply_closure1_closure2.doCall(RobolectricPlugin.groovy:31)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:63)
    at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
    at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:115)
    at org.gradle.api.DomainObjectCollection$all$1.call(Unknown Source)
    at org.robolectric.gradle.RobolectricPlugin$_apply_closure1.doCall(RobolectricPlugin.groovy:27)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:83)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy13.afterEvaluate(Unknown Source)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
    ... 28 more


BUILD FAILED

次に、別のプラグイン、つまり com.github.jcandksolutions.gradle:android-unit-test:2.1.1' を試しましたが、まだ機能しませんでした。以下は、グレード構築スクリプトと出力です。

//http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
        maven { url 'http://www.testfairy.com/maven' }
    }

    dependencies {
        classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
        classpath 'com.testfairy.plugins.gradle:testfairy:1.+'
        classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'testfairy'


repositories {
    mavenCentral()
    maven { url 'http://download.crashlytics.com/maven' }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    testBuildType "debug"
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    apply plugin: 'android-unit-test'
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        testApplicationId "com.project..test"
//        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        //testInstrumentationRunner "com.lproject.test.Runner"
        manifestPlaceholders = [ adxUseQaServerEnabled: "ON" ]
    }

    testfairyConfig {
        apiKey "xxxxx"
        metrics "cpu,memory,network,logcat"
        video "wifi"
        videoRate "0.5"
        videoQuality "low"
        maxDuration "10m"
        recordOnBackground true
        iconWatermark true
        testersGroups "xxxx"
        notify true
        maxDuration "1h"
        autoUpdate true
        uploadProguardMapping true
    }

    productFlavors {
        //testing {
        //}
        local {
        }
        mock {
        }
        qa {
        }
        //qa4 {
        //}
        production {
        }
    }

    sourceSets {
        local {
            res.srcDir 'build-config/local/res'
        }
        testing {
            res.srcDir 'build-config/testing/res'
        }
        mock {
            res.srcDir 'build-config/mock/res'
        }
        qa {
            res.srcDir 'build-config/qa/res'
        }
        qa4 {
            res.srcDir 'build-config/qa4/res'
        }
        staging {
            res.srcDir 'build-config/staging/res'
        }
        production {
            res.srcDir 'build-config/production/res'
        }
        instrumentTest.setRoot('src/test')
    }

    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-project.txt'
            signingConfig signingConfigs.release
            manifestPlaceholders = [ adxUseQaServerEnabled:"OFF" ]
        }
        debug {
            versionNameSuffix "-debug"
        }
    }
}

android.lintOptions {
    disable 'InvalidPackage'
    abortOnError false
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:support-v4:19.1.+'
    compile 'com.android.support:appcompat-v7:19.1.+'
    compile 'com.google.android.gms:play-services:5.0.+'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile "joda-time:joda-time:2.4"
    androidTestCompile ('junit:junit:4.12') {
        exclude module : 'hamcrest'
        exclude module : 'hamcrest-core'
    }
    androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
    androidTestCompile ('org.mockito:mockito-core:1.9.5') {
        exclude module : 'hamcrest'
        exclude module : 'hamcrest-core'
    }
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.sothree.slidinguppanel:library:3.0.0'

    compile 'com.jakewharton:butterknife:6.1.0'

    androidTestCompile('org.robolectric:robolectric:2.3') {
        exclude module: 'classworlds'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-plugin-registry'
        exclude module: 'maven-profile'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        exclude module: 'nekohtml'
        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-http-shared'
        exclude module: 'wagon-provider-api'
        exclude module: 'objenesis'
    }


}

エラー

AILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ‘:projectName’.
> java.lang.NullPointerException (no error message)


 Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ‘:projectName’.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:91)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:86)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:65)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.lang.NullPointerException
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.extendsFrom(DefaultConfiguration.java:148)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper$_getConfiguration_closure4.doCall(VariantWrapper.groovy:177)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper.getConfiguration(VariantWrapper.groovy:176)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper.getProperty(VariantWrapper.groovy)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper.getClasspath(VariantWrapper.groovy:190)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper.getProperty(VariantWrapper.groovy)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper.configureSourceSet(VariantWrapper.groovy:83)
    at com.jcandksolutions.gradle.androidunittest.VariantWrapper$configureSourceSet.call(Unknown Source)
    at com.jcandksolutions.gradle.androidunittest.MainHandler$_run_closure1.doCall(MainHandler.groovy:49)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:63)
    at org.gradle.listener.ActionBroadcast.execute(ActionBroadcast.java:39)
    at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:165)
    at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:160)
    at com.android.build.gradle.AppExtension.addVariant(AppExtension.groovy:58)
    at com.android.build.gradle.internal.VariantManager.createVariantApiObjects(VariantManager.java:624)
    at com.android.build.gradle.internal.VariantManager.createApiObjects(VariantManager.java:591)
    at com.android.build.gradle.internal.VariantManager.createAndroidTasks(VariantManager.java:226)
    at com.android.build.gradle.internal.VariantManager$createAndroidTasks$0.call(Unknown Source)
    at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.groovy:463)
    at com.android.build.gradle.BasePlugin$_createTasks_closure9.doCall(BasePlugin.groovy:408)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:83)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy13.afterEvaluate(Unknown Source)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
    ... 28 more
4

1 に答える 1

0

これは、targetSdkVersion が 19 であるためです。Robolectric は最大をサポートしています: 18

于 2015-04-01T13:00:42.783 に答える