robolectric/robolectric-gradle-plugin

Could not find method afterTest() on project ':app'

mdumrauf opened this issue · 2 comments

Given this project descriptor:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.12.2'
    classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+'
  }
}
apply plugin: 'com.android.application'
apply plugin: 'robolectric'

android {
  compileSdkVersion 19
  buildToolsVersion "19.1.0"

  defaultConfig {
    applicationId "com.foo.bar"
    minSdkVersion 16
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
      runProguard false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

  packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
  }
}

dependencies {
  compile project(':eventbus')
  compile project(':network')

  androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
  androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
  androidTestCompile 'org.hamcrest:hamcrest-library:1.1'

  androidTestCompile('junit:junit:4.11') {
    exclude module: 'hamcrest-core'
  }
  androidTestCompile('org.robolectric:robolectric:2.3') {
    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'
  }
}

robolectric {
  include '**/*Test.class'
  maxHeapSize = '2048m'
  ignoreFailures true

  afterTest { descriptor, result ->
    println "Executing test for {$descriptor.name} with result: ${result.resultType}"
  }
}

Y run ./gradlew test --stacktrace and get this output:

$ ./gradlew clean test --stacktrace

FAILURE: Build failed with an exception.

* Where:
Build file '/home/mdumrauf/workspace/java/android/Foo/app/build.gradle' line: 63

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method afterTest() for arguments [build_8qimn5atgapaohm4ce1rgg3a0$_run_closure3_closure10@7ac260c5] on project ':app'.

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:152)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:40)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:493)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:80)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    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:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
    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:46)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.Main.main(Main.java:37)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method afterTest() for arguments [build_8qimn5atgapaohm4ce1rgg3a0$_run_closure3_closure10@7ac260c5] on project ':app'.
    at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)
    at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:172)
    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
    at build_8qimn5atgapaohm4ce1rgg3a0$_run_closure3.doCall(/home/matias/workspace/java/android/ControlRemote/app/build.gradle:63)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58)
    at org.gradle.api.internal.plugins.ExtensionsStorage$ExtensionHolder.configure(ExtensionsStorage.java:145)
    at org.gradle.api.internal.plugins.ExtensionsStorage.configureExtension(ExtensionsStorage.java:69)
    at org.gradle.api.internal.plugins.DefaultConvention$ExtensionsDynamicObject.invokeMethod(DefaultConvention.java:213)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
    at build_8qimn5atgapaohm4ce1rgg3a0.run(/home/matias/workspace/java/android/ControlRemote/app/build.gradle:58)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    ... 33 more


BUILD FAILED

Total time: 3.099 secs

The README is misleading here. This feature wasn't part of the 0.12.0 release ( https://github.com/robolectric/robolectric-gradle-plugin/tree/0.12.0 ). You have to wait for the next release to use this feature.

But anyhow: You can remove the whole robolectric { … } DSL part of your build.gradle as this is purely optional to tweak/extend the normal behaviour.

erd commented

This should be in the current release.