mannodermaus / android-junit5 Goto Github PK
View Code? Open in Web Editor NEWTesting with JUnit 5 for Android.
License: Apache License 2.0
Testing with JUnit 5 for Android.
License: Apache License 2.0
Hi
I have this basic android library project
apply plugin: 'com.android.library'
apply plugin: 'de.mannodermaus.android-junit5'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.androidVersionCode
versionName rootProject.ext.androidVersionName
testInstrumentationRunner rootProject.ext.testInstrumentationRunner
}
}
junitPlatform {
jupiterVersion rootProject.ext.jupiterVersion
platformVersion rootProject.ext.junitPluginVersion
}
dependencies {
compile project(':domain')
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "io.reactivex.rxjava2:rxkotlin:$rxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
// Dependencies for local unit tests
testCompile junitJupiter()
testCompile "org.assertj:assertj-core:$assertjVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
}
When I run gradlew test my test's are being ignore, anything obvious I am missing? Are libraries supported?
I try to run robolectric test with junit5 and run into an issue. Because of some library I use I need to a -noverify
to the jvm arguments. Previously (with junit4) this worked like this:
testOptions {
unitTests {
all {
// configure the test JVM arguments
jvmArgs '-noverify'
}
}
}
But unfortunately this does not work with junit5 and this plugin. I'm not sure, but it seems the plugin does not use the provided jvm arguments.
Add the kotlin output directory to the classpath Instead of copying kotlin classes to intermediates
folder. Was able to do it in Spek's AS plugin by using an API provided by AS3 (see https://github.com/raniejade/spek-idea-plugin/blob/master/plugin-studio3.0/src/main/kotlin/org/jetbrains/spek/studio/SpekAndroidParameterPatcher.kt). Probably the same API is available in AGP3. Some users are reporting issues caused by the copy during dexing, removing the copy tasks fixes the issue.
I see the XML output, but I don't see anyway to configure the plugin to output HTML. Is that supported?
Can you update this https://github.com/aurae/android-junit5/blob/a51a6eb6af48aa8efd2de9fb4e63a7794a5b7c35/gradle.properties#L12
to JUNIT_PLATFORM_VERSION=1.0.0-M3
I am currently facing junit-team/junit5#576 with this plugin, so I am assuming going to M3 will help? which is showing me
Caused by: org.junit.platform.joptsimple.UnrecognizedOptionException: all is not a recognized option
This plugin seems to have problems with Android Gradle Plugin (AGP) 2.4.0-alpha7 (works fine with 2.3.2)
With AGP 2.4.0-alpha7 I get this error:
Looks like the test engines are not on the classpath for the ConsoleLauncher invocation.
org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:285)
at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:52)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:61)
at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57)
at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:79)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:69)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:41)
Option Description
------ -----------
-h, --help Display help information.
--disable-ansi-colors Disable ANSI colors in output (not
supported by all terminals).```
I added default config to my project and I receive following error. The strange things, that it outputs some results before shown error.
Test run finished after 218372 ms
[ 56 containers found ]
[ 0 containers skipped ]
[ 56 containers started ]
[ 0 containers aborted ]
[ 56 containers successful ]
[ 0 containers failed ]
[ 441 tests found ]
[ 5 tests skipped ]
[ 436 tests started ]
[ 0 tests aborted ]
[ 401 tests successful ]
[ 35 tests failed ]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:junitPlatformTestFullDebug'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:junitPlatformTestFullDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:380)
at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:31)
at org.gradle.api.tasks.JavaExec.exec(JavaExec.java:74)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:731)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
Just in case:
-OS - OS X 10.12.6
-JVM - jdk 1.8.0_162
Thanks alot for your work. i use your gradle plugin with the latest Android Studio Preview (currently RC2) and within my Android Studio everything works like a charm. But i have now an issue using it with my CI System. if i run the test task with ./gradlew it always finds 0 tests. I created a plain app and gradle finds the tests with the default runner, after migrating it to junit5 it can't find the tests:
Running ./gradlew testDebugUnit
Test run finished after 64 ms
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
Gradle Project:
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.10"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle app module:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "de.mannodermaus.android-junit5"
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "ch.rethinc.gradleunittest"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
junitPlatform {
jupiterVersion '5.0.1'
vintageVersion '4.12.1'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation junit5()
testImplementation junit5Params()
testCompileOnly junit5EmbeddedRuntime()
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
And my failing unit test located in the test folder:
package ch.rethinc.gradleunittest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 1)
}
}
Best Regards
Chris
Right, I don't know if this is an issue with this plugin or our general setup but here goes:
We have a test class under src/test/kotlin/Test.kt
. It references a test helper class located in src/test/java/Helper.java
This is in an Android library module
.
The tests fail to compile, the kotlin class cannot see the java class. We get UnresolvedReference
errors for anything from the src/kotlin
folder that refers to stuff from src/java
.
With the stable release of AS 3.1, the foundation of IntelliJ is finally based on a stable JUnit 5 version as well, so we don't need to worry about NoSuchMethodError
s from outdated internal classes anymore. Usage of the junit5.unitTestsRuntime()
dependency should trigger a warning in the IDE in the next release, and should be removed in the one after that.
The Android Gradle Plugin used to have its own jacoco
container, however that has since been deprecated. When using our junitPlatform.jacoco
DSL inside the Android testOptions
, Android Studio confuses it with the deprecated container and renders an undesirable strikethrough.
We should consider renaming the container to jacocoOptions
.
I just want to leave a note, that current version of the plugin (1.0.31) causes project with canary version of Android Gradle Plugin 3.2 to fail when syncing.
Here's the full stack trace:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':feature_cart'.
> Failed to notify project evaluation listener.
> UNIT_TEST
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
โช ./gradlew clean assembleDebug --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':feature_cart'.
> Failed to notify project evaluation listener.
> UNIT_TEST
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':feature_cart'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:89)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:667)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:136)
at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:62)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:261)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:173)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:49)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:86)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy24.afterEvaluate(Unknown Source)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:76)
... 81 more
Caused by: java.lang.NoSuchFieldError: UNIT_TEST
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.getDefaultJUnit4Task(UnitTest.kt:148)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.configureTaskDependencies(UnitTest.kt:191)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.execute(UnitTest.kt:100)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.execute(UnitTest.kt:78)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:151)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$Companion.create(UnitTest.kt:55)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$configureTasks$1.execute(Plugin.kt:100)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$configureTasks$1.execute(Plugin.kt:24)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:136)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin.configureTasks(Plugin.kt:96)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin.access$configureTasks(Plugin.kt:24)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$apply$3.execute(Plugin.kt:43)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$apply$3.execute(Plugin.kt:24)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:91)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:80)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
... 88 more
I'm trying to set up HTML reporting for my tests. I've noticed that the test tasks are generated in project.afterEvaluate
. This is the exact same hook I use to find the test tasks, so it's a bit of a chicken-and-egg problem - it works on the command line for some reason but fails in Android Studio - can't find the test tasks.
I use something like
project.afterEvaluate {
if (project.coverage.includes == null) {
project.coverage.includes = []
}
// Grab all build types and product flavors
def buildTypes = android.buildTypes.collect { type ->
type.name
}
def productFlavors = android.productFlavors.collect { flavor ->
flavor.name
}
// When no product flavors defined, use empty
if (!productFlavors) productFlavors.add('')
def coverageTasks = []
buildTypes.each { buildTypeName ->
productFlavors.each { productFlavorName ->
def capitalizedVariantName
if (!productFlavorName) {
capitalizedVariantName = "${buildTypeName.capitalize()}"
} else {
capitalizedVariantName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}"
}
def testTaskName = "junitPlatformTest${capitalizedVariantName}"
// Add HTML reports for JUnit 5
tasks[testTaskName].finalizedBy 'junitHtmlReport'
}
}
tasks['junitPlatformTest'].finalizedBy 'junitHtmlReport'
}
Do you have any better suggestion on how I can hook this up?
Instead of duplicating junitPlatform.jacoco
parameters, the tasks generated for test coverage by the plugin should obey whatever is configured through the main jacoco
closure.
In Android Studio 2.3.3, applying:
apply plugin: 'com.android.library'
apply plugin: 'de.mannodermaus.android-junit5'
junitPlatform {
jupiterVersion "5.0.1"
platformVersion "1.0.1"
}
dependencies {
...
testCompile junit5()
testCompile "de.mannodermaus.gradle.plugins:android-junit5-embedded-runtime:1.0.0-RC3-rev1"
}
I get this exception:
Exception in thread "main" java.lang.AbstractMethodError:
com.intellij.junit5.JUnit5IdeaTestRunner.setStreams(Ljava/lang/Object;Ljava/lang/Object;I)V
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:261)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
I've stripped your sample and tried to run it with Android Studio 3.0 Beta 4 64-bit on Windows, but it fails with the following error:
"C:\Program Files\Java\jdk1.8.0_141\bin\java" ...
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Process finished with exit code 1
From previous issues I've gathered that this release should work out-of-the-box with the preview editions of Android Studio. However, I've also tried the workarounds mentioned in JUnit 5 docs for IntelliJ IDEA without any luck.
Running from command line works fine:
sample โฏโฏโฏ .\gradlew.bat testDebugUnitTest
> Task :junitPlatformTestDebug
@BeforeAll
@Before Test taggedTest()
@After Test taggedTest()
@Before Test ordinaryTestCase()
@After Test ordinaryTestCase()
@Before Test dynamicTestsGeneratedFromFactory()
@After Test dynamicTestsGeneratedFromFactory()
@Before Test [1] Android's Cool!
@After Test [1] Android's Cool!
@Before Test [2] JUnit 5 as well
@After Test [2] JUnit 5 as well
@Before Test [3] Acknowledgement
@After Test [3] Acknowledgement
@Before Test Test with Custom Display Name in nested class
@After Test Test with Custom Display Name in nested class
@AfterAll
Test run finished after 2465 ms
[ 6 containers found ]
[ 0 containers skipped ]
[ 6 containers started ]
[ 0 containers aborted ]
[ 6 containers successful ]
[ 0 containers failed ]
[ 10 tests found ]
[ 1 tests skipped ]
[ 9 tests started ]
[ 0 tests aborted ]
[ 9 tests successful ]
[ 0 tests failed ]
BUILD SUCCESSFUL in 6s
17 actionable tasks: 1 executed, 16 up-to-date
I've attached the stripped project if it matters: android-junit5-sample.zip
When I run tests on 3 different app flavors, the test outputs all land under app/build/test-results/junit-platform/TEST-junit-vintage.xml
. This effectively means that if I want to get test results for 3 different flavors independently I can't because they overwrite each other.
I would expect them to land under separate folders like
app/build/test-results/vanillaDebug/junit-platform/TEST-junit-vintage.xml
app/build/test-results/chocolateDebug/junit-platform/TEST-junit-vintage.xml
app/build/test-results/pistachioDebug/junit-platform/TEST-junit-vintage.xml
Hi, have a small problem when use plugin: I need to add custom exclude to jacocoTestReportDebug coverage. Is there any way to do this?
When I try to define the same task generated by plugin gradle give me the error that task with this name already exists.
task "jacocoTestReport${buildVariantName.capitalize()}"(type: JacocoReport, dependsOn: testTaskName) {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: "$buildDir/intermediates/classes/$buildVariantName",
// want to see coverage only to specific packages, classes
include: [
'**/MathUtils.class'
]
)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
executionData = files("${buildDir}/jacoco/${testTaskName}.exec")
reports {
html.enabled = true
}
}
And the second question: I don't need to create jacoco tasks for all build variants.Is it possible to prevent plugin from generating this tasks? Is there possibility to manage jacoco tasks only in client code?
gradlew testDebug --tests="*ClassName*"
Running the junitPlatformTest task doesn't generate an EXEC code coverage file.
Example of someone getting JaCoCo code coverage working with JUnit 5: http://stackoverflow.com/questions/39362955/gradle-jacoco-and-junit5
When running tests, get this:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.Preconditions.notNull([Ljava/lang/Object;Ljava/lang/String;)[Ljava/lang/Object;
at org.junit.platform.launcher.core.DefaultLauncher.registerTestExecutionListeners(DefaultLauncher.java:71)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:37)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Any idea?
Hi,
I try to implement instrumented unit tests.
I work with Android Studio 3.0.1
My top Level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.30"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app-level build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: "de.mannodermaus.android-junit5"
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.todo.app"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
// Configuration closure added by the plugin;
// all configurable parameters related to JUnit 5 can be found here
junitPlatform {
// The JUnit Jupiter dependency version to use
jupiterVersion "5.0.3"
// The JUnit Vintage Engine dependency version to use
vintageVersion "4.12.2"
// Options related to running unit tests with JUnit 5.
unitTests {
// Whether or not JUnit 5 test tasks should be affected by
// JVM Arguments, System Properties & Environment Variables
// declared through "unitTests.all" closures
applyDefaultTestOptions true
}
// Options related to running instrumented tests with JUnit 5.
// This is an incubating feature which utilizes the backwards-compatibility
// of the JUnit Platform in order to enhance the default Test Instrumentation Runner
// with new power. However, because of their experimental nature and steep minSdkVersion requirement,
// they are turned off by default. If you choose to enable them, you also have to declare
// the library dependency in your androidTest scope. Please refer to the "Setup"
// section for more details.
instrumentationTests {
enabled true
// The Android-Instrumentation-Test dependency version to use
version "0.1.1"
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.3'
testCompile "org.mockito:mockito-core:2.13.0"
// (Required) Writing and executing Unit Tests on the JUnit Platform.
testImplementation junit5.unitTests()
// (Optional) If you need "Parameterized Tests".
testImplementation junit5.parameterized()
// (Optional) For running tests inside Android Studio 3.x
testCompileOnly junit5.unitTestsRuntime()
androidTestImplementation junit5.instrumentationTests()
}
repositories {
mavenCentral()
}
apply plugin: 'kotlin-android-extensions'
Under src/androidTest/java/com.myapp.app/ExempleInstrumentedTest my test:
package com.todo.app
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class ExampleInstrumentedTest {
@Test
fun test() {
// Read the data.
assertEquals(true, true, "test")
}
}
When I try to launch this test I got this error (on android studio):
fรฉvr. 01, 2018 7:48:50 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
AVERTISSEMENT: TestEngine with ID 'junit-jupiter' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.todo.app.ExampleInstrumentedTest
and
fรฉvr. 01, 2018 7:48:50 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
AVERTISSEMENT: TestEngine with ID 'junit-vintage' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.todo.app.ExampleInstrumentedTest
Process finished with exit code 0
Empty test suite.
What is the problem ?
It looks like the test results (for JUnit 5-style tests) are not written to $buildDir\test-results\junit-platform\TEST-junit-jupiter.xml
Ordinary JUnit4 tests are properly reported to: $buildDir\test-results\junit-platform\TEST-junit-vintage.xml
however.
A project with two tests, one regular old school JUnit 4 test:
public class FooTest {
@org.junit.Test
public void foo() {}
}
One JUnit5 test:
class FooTests {
@org.junit.jupiter.api.Test
void foo() {}
}
Run goal: gradlew testDebug
Open folder: build\test-reults\junit-platform\
Compare the two XML files (TEST-junit-vintage.xml
and TEST-junit-jupiter.xml
). In the vintage XML I find lines such as:
<testcase name="HashCode_WithTwoEqualInstances_ReturnsSameHashCode" classname="com.censored.FooTest" time="0">
<system-out><![CDATA[
unique-id: [engine:junit-vintage]/[runner:com.censored.FooTest]/[test:HashCode_WithTwoEqualInstances_ReturnsSameHashCode(com.censored.FooTest)]
display-name: HashCode_WithTwoEqualInstances_ReturnsSameHashCode
]]></system-out>
</testcase>
No such entries in the jupiter file.
Please confirm that this is not just my environment playing a prank on me.
JaCoCo includes all classes in its report. To exclude classes, the plug-in needs to set the task's class directories like this:
reportTask.classDirectories = project.fileTree(
dir: <destinationDir>,
excludes: ['**/R.class', '**/R$*.class']
)
Right now, while the plugin works out-of-the-box with Gradle's Kotlin-based DSL, this integration can be improved quite significantly. Some examples:
// Ew:
android {
testOptions {
junitPlatform.apply {
details = Details.TREE
}
}
}
// Better:
android {
testOptions {
junitPlatform {
details = Details.TREE
}
}
}
// Ew!!
dependencies {
val junit5 = dependencies.ext["junit5"] as JUnit5DependencyHandler
junit5.unitTests().forEach { testCompile(it) }
junit5.parameterized().forEach { testCompile(it) }
}
// Better:
dependencies {
testCompile(junit5.unitTests())
testCompile(junit5.parameterized())
}
Let's analyze how this can be validated using unit tests, so we can ensure better compatibility with users of the Kotlin-based Gradle build scripts. This might require removing some deprecated APIs (e.g. ExtensionProxy
) in the process.
Tracked in branch feature-plugin-support
Following up on the previous issues with the alpha versions of the Android Gradle Plugin, I went ahead and tried the latest alpha07 with the plugin, and of course there is yet another breaking change. :|
e: android-junit5/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt: (186, 31): Type mismatch: inferred type is BuildableArtifact! but FileCollection? was expected
:android-junit5:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':android-junit5:compileKotlin'.
> Compilation error. See log for more details
Supposedly, the type of assetsCollection
changed. Let's look into this.
With Gradle 4.6, native support for JUnit 5 will arrive has arrived. It'll be interesting to see the extent of how this integration can be leveraged on Android as well. Potentially, the plugin would get a major overhaul, splitting up into compat mode (the current implementation, using JavaExec
tasks) and native mode (using Test
tasks and the improvements in 4.6).
I added dependency like described at Readme file
. I use AS 3.0.
build.gradle file:
apply plugin: 'com.android.application'
apply plugin: "de.mannodermaus.android-junit5"
android {
compileSdkVersion 26
defaultConfig {
applicationId "colibri.dev.com.juni5sample"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
testImplementation junit5()
// (Optional) For running tests inside Android Studio 3.x (see below for details)
testCompileOnly junit5EmbeddedRuntime()
}
top-level build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.21"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And catch exception:
Unable to find method 'org.gradle.api.internal.TaskInputsInternal.property(Ljava/lang/String;Ljava/lang/Object;)Lorg/gradle/api/tasks/TaskInputPropertyBuilder;'. Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
The README still mentions M6 but it seems like the code has been updated to support RC3?
Android studio doesn't recognise the tests when I use this plugin.
After applying unitTestsRuntime() in gradle AS3 doesnt run android tests as android test and run it as unit test without asking (as it was before)
I'm still getting some classpath-related errors when either trying to run the JUnit 5 Gradle task, or using AS' built-in "Run Tests" feature. In some projects, only one of the methods works, other times, both do. It has to be related to the way the classpath is set up & prepared for unit tests.
The custom RunnerBuilder
, which is at the heart of our instrumentation test support, is currently bundled with the other stuff related to instrumented tests, and it shouldn't be. We could make the integration more seamless if we extracted it into its own artifact, then automatically applied it to projects that enable instrumented tests.
When running tests from the command line - ./gradlew test - It seems neither JUnit4 or JUnit5 tests are picked up in library modules. Test detection works fine in the app module, or any module using the 'com.android.application' plugin.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.20"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.31"
}
}
apply plugin: 'com.android.library'
apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
dataBinding {
enabled = true
}
kapt {
generateStubs = true
}
testOptions {
junitPlatform {
jupiterVersion "5.0.3"
vintageVersion "4.12.2"
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
...
testImplementation junit5.unitTests()
testImplementation junit5.parameterized()
testCompileOnly junit5.unitTestsRuntime()
}
I'm not entirely sure that this plugin is causing my problems, but I'm unable run my tests via gradle on the console. It works if I run them via android studio, but if I try to run the gradle task manually it fails with java.io.IOException: CreateProcess error=206, The filename or extension is too long
.
This seems to be a known problem on windows Mitigate Long Path Issues Automatically #1989.
Also if I disable the plugin executing the test works (But only junit4 tests are executed...).
Entire stacktrace:
stacktrace.txt
JUnit5 does not support Rule
s. Yet some tests, particularly Android tests, absolutely require Rule
s. One example is the InstantTaskExecutorRule
required for unit testing ViewModel
s. I'm interested in writing a custom Extesnsion, but I don't really know where to start. Any ideas? Does this already exist?
Gradle 4.5, Android Gradle plugin 3.2.0-alpha02
When running a build which worked with previous version of the Android Gradle Plugin with V3.2.0-alpha2 the configuration phase fails with the following exception:
Caused by: java.lang.NoSuchMethodError: com.android.build.gradle.internal.scope.VariantScope.getJavaOutputDir()Ljava/io/File;
at de.mannodermaus.gradle.plugins.junit5.providers.JavaDirectoryProvider.classFoldersOf(Java.kt:27)
at de.mannodermaus.gradle.plugins.junit5.providers.JavaDirectoryProvider.mainClassDirectories(Java.kt:16)
at de.mannodermaus.gradle.plugins.junit5.providers.DirectoryProvider$DefaultImpls.classDirectories(Base.kt:29)
at de.mannodermaus.gradle.plugins.junit5.providers.JavaDirectoryProvider.classDirectories(Java.kt:12)
at de.mannodermaus.gradle.plugins.junit5.providers.BaseKt.classDirectories(Base.kt:49)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.execute(UnitTest.kt:113)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$ConfigAction.execute(UnitTest.kt:76)
at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:151)
at de.mannodermaus.gradle.plugins.junit5.tasks.AndroidJUnit5UnitTest$Companion.create(UnitTest.kt:57)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$configureTasks$1.execute(Plugin.kt:93)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$configureTasks$1.execute(Plugin.kt:21)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:136)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin.configureTasks(Plugin.kt:89)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin.access$configureTasks(Plugin.kt:21)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$apply$2.execute(Plugin.kt:36)
at de.mannodermaus.gradle.plugins.junit5.AndroidJUnitPlatformPlugin$apply$2.execute(Plugin.kt:21)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:91)
at org.gradle.internal.event.BroadcastDispatch$ActionInvocationHandler.dispatch(BroadcastDispatch.java:80)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:230)
at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:149)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:324)
at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:234)
at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:140)
at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy24.afterEvaluate(Unknown Source)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:76)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:667)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:136)
at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:62)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:249)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:167)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:126)
at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:109)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:49)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)```
Android Gradle Plugin 3.0.0 changed the way Java outputs are reported to variants, because I'm getting the following after updating:
Error:No such property: javaOuptuts for class: com.android.build.gradle.internal.scope.VariantScopeImpl
This is related to a fallback because of a typo in older versions of the AGP. The JUnit 5 plugin tries to obtain the values from the correct property, using "javaOutputs" first, then falling back to the misspelled "javaOuptuts". This is an example of our usage. I need to review what changed within VariantScope, and apply that accordingly.
We have been using the junitPlatform
configuration closure in the same place as the Java-based plugin, however it would be preferable to use either android.defaultConfig
or android.testOptions
in Android environments.
In the README it says:
apply plugin: 'com.android.application'
apply plugin: "de.mannodermaus.android-junit5"
What about Android library modules? Can you confirm that this works:
apply plugin: 'com.android.library'
apply plugin: "de.mannodermaus.android-junit5"
?
I'm struggling myself to get a working configuration so sorry for the stupid question. I looked at the sample project but unfortunately it's single module and not showing my setup (multi-module with Android library modules)
I'm getting an error for this line (in the android library submodule):
dependencies {
testImplementation junit5() <-----
}
Stacktrace:
Could not find method testImplementation() for arguments [[DefaultExternalModuleDependency{group='junit', name='junit', version='4.12', configuration='default'}, DefaultExternalModuleDependency{group='org.junit.jupiter', name='junit-jupiter-api', version='5.0.0', configuration='default'}, DefaultEx
ternalModuleDependency{group='org.junit.platform', name='junit-platform-engine', version='1.0.0', configuration='default'}, DefaultExternalModuleDependency{group='org.junit.platform', name='junit-platform-launcher', version='1.0.0', configuration='default'}, DefaultExternalModuleDependency{group='org
.junit.platform', name='junit-platform-console', version='1.0.0', configuration='default'}, DefaultExternalModuleDependency{group='org.junit.jupiter', name='junit-jupiter-engine', version='5.0.0', configuration='default'}, DefaultExternalModuleDependency{group='org.junit.vintage', name='junit-vintage
-engine', version='4.12.0', configuration='default'}]] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Update:
testImplementation is new in the upcoming (not released) Android Gradle Plugin...
Changing to testCompile seems to work. I'm able to run the tests but not getting any code coverage due to a missing "junitPlatformTest" task. Is this task called something else using this plugin?
With junit 4 tests we had the ability to configure the number of Java process forks that would run a big test suite and therefor speed the run up substantially. This was possible via
testOptions.unitTests.all {
maxParallelForks 2
}
Each fork normally uses four threads (afaik this is some internal junit configuration that cannot be changed), so this setup would lead to a total of 8 threads running a test suite.
Unfortunately, with the android-junit5 plugin, the above configuration no longer works. Do you know an alternative how to configure this now? I also cannot find any reference to it in the junitPlatform
DSL of the official Gradle plugin.
Hi, I've been able to set up the plugin for my current project but seem to have an issue when I take a look at the Jacoco report. The current Jacoco report doesn't allow me to see highlighted pieces of code to better know which were covered by tests and which I missed.
Reading the FAQ from Jacoco I noticed it was related to to the sourceDirectories and classDirectories of the project but I can't seem to specify them under the jacocoOptions portion. Does this need to be done in a different area or specified in a different way?
With Gradle 4.6 out in the wild and the junit5-team plugin about to be deprecated in a future release, let's look at moving the Android plugin to the native JUnit 5 support as well. To minimize tedious compatibility effort, this will raise the minimum Gradle requirement to 4.6 in the process.
Deliverables
JavaExec
tasksNew alpha, new breaking changes incoming? Let's find out.
When I'm using plugin jacoco executes tests for all build variants. I specified that jacocoTestReport only depends on one task with name "test${testBuildVariantName.capitalize()}UnitTest", but when I run task it executes tests for all build types. I started watch source code of plugin, but will be thankful if you point me to the right direction to increase this process
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.