23

I am using Intellij 2019.2 to run gradle test cases, however, I keep getting the following exception. According to some posts, I have done the following:

  1. Add junit(junit-jupiter-api:5.3.1) dependencies as testImplementation and
  2. Put useJUnitPlatform() in build.gradle file
  3. Set Intellij's gradle runner to use Gradle(Default) to run my test cases.

The issue still exist after above steps.

Could someone give me some hint about how to get rid of this error ? Really appreciate

   Caused by: org.gradle.api.tasks.testing.TestExecutionException: No tests found for given includes: [***Test](filter.includeTestsMatching)
                at org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter.afterSuite(NoMatchingTestsReporter.java:37)
                at jdk.internal.reflect.GeneratedMethodAccessor307.invoke(Unknown Source)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
                at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
                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.$Proxy99.afterSuite(Unknown Source)
                at org.gradle.api.internal.tasks.testing.results.TestListenerAdapter.completed(TestListenerAdapter.java:48)
                at jdk.internal.reflect.GeneratedMethodAccessor325.invoke(Unknown Source)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
                at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
                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.$Proxy101.completed(Unknown Source)
                at org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor.completed(StateTrackingTestResultProcessor.java:96)
                at org.gradle.api.internal.tasks.testing.results.AttachParentTestResultProcessor.completed(AttachParentTestResultProcessor.java:56)
                at org.gradle.api.internal.tasks.testing.processors.TestMainAction.run(TestMainAction.java:60)
                at org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter.execute(DefaultTestExecuter.java:116)
                at org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter.execute(DefaultTestExecuter.java:51)
                at org.gradle.api.tasks.testing.AbstractTestTask.executeTests(AbstractTestTask.java:483)
                at org.gradle.api.tasks.testing.Test.executeTests(Test.java:587)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
                at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:48)
                at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
                at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
                at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
                at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:672)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$4.run(ExecuteActionsTaskExecuter.java:338)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
                at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
                at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:327)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:312)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:75)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:158)
                at org.gradle.internal.execution.impl.steps.ExecuteStep.execute(ExecuteStep.java:46)
                at org.gradle.internal.execution.impl.steps.CancelExecutionStep.execute(CancelExecutionStep.java:34)
                at org.gradle.internal.execution.impl.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:69)
                at org.gradle.internal.execution.impl.steps.TimeoutStep.execute(TimeoutStep.java:49)
                at org.gradle.internal.execution.impl.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34)
                at org.gradle.internal.execution.impl.steps.CreateOutputsStep.execute(CreateOutputsStep.java:49)
                at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:42)
                at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:28)
                at org.gradle.internal.execution.impl.steps.CacheStep.executeWithoutCache(CacheStep.java:133)
                at org.gradle.internal.execution.impl.steps.CacheStep.lambda$execute$5(CacheStep.java:83)
                at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:82)
                at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:37)
                at org.gradle.internal.execution.impl.steps.PrepareCachingStep.execute(PrepareCachingStep.java:33)
                at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:38)
                at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:23)
                at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:95)
                at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:88)
                at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:52)
                at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
                at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:34)
                at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:109)
                ... 129 more```



4
  • Does it work from command-line? Do you have tests matching src/test/java/**/*Test.java? etc
    – drekbour
    Commented Oct 20, 2019 at 19:44
  • @drekbour In my Intellij, I have both java 1.8 and java 11.0.4. This project needs to be run using java 11.0.4. Intellij is using C:\Users***\AppData\Local\JetBrains\IntelliJ IDEA 2019.2.3\jbr as JDK home path. Do you think this is the issue? I am not able to run test cases using command line since I don't have Java 11 installed on my computer.
    – Guifan Li
    Commented Oct 20, 2019 at 20:00
  • Is it possible to provide little sample project where the issue is reproduced? Commented Oct 21, 2019 at 10:25
  • I had the same problem and resolved selecting the option menu "Create Test Configuration" that appears between the "Run ... with Coverage" and "Show in explorer" option when select a test file and right click to show the menu.
    – mabg
    Commented Oct 24, 2019 at 18:36

9 Answers 9

27

I'm not sure if this will help, but I changed the import statement on my test class, for the test decorator, from import org.junit.Test to import org.junit.jupiter.api.Test and that seems to have fixed this problem.

0
15

Just add

tasks.withType(Test) {
    useJUnitPlatform()
}

to your app

build.gradle > root

file. In my case I had following for logging:

tasks.withType(Test) {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}
6

Faced this issue after upgrading to Android Studio Chipmunk. Resolved it by REMOVING the following code from module's build.gradle:

tasks.withType(Test) {
    useJUnitPlatform()
}

Looks like this configuration was one of the ways to resolve this issue on the prior versions of Android Studio (or AGP), but became a source of the problem by itself due to some new changes.

3

I had the same issue. After running gradle in debug mode --debug mode, the console was containing a ClassNotFoundException for org.junit.platform.commons.PreconditionViolationException.

Issue was fixed by adding:

testImplementation 'org.junit.platform:junit-platform-commons:1.5.2'
1
  • Question is, why is an error like ClassNotFoundException visible only at debug level? It's been a while, but any chance you can post the complete log statement? Gradle debug spits out so much garbage it's almost unusable. Commented Sep 10, 2020 at 18:28
2

I was facing the same issue. Initially, I had 2 dependencies in my Gradle project because of that I was getting the issue. The first two dependencies were the following :

compile "org.codehaus.groovy:groovy-all:2.5.8"
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"

Then I added 3rd dependency which resolved the issue.

testCompile platform("org.spockframework:spock-bom:2.0-M1-groovy-2.5")
2

It was making all the test functions public that solved my problem.

1

One of the causes of this Exception is using Default access modifier in Java.

JUnit test methods should avoid the following: declared static, not declared public, do not return void, or have parameters.

Such test methods are easy to create inadvertently, but they will not be executed by JUnit test runners.

So instead of this:

@Test
void test() {
   assertEquals(1, 1);
}

Add public like this:

@Test
public void test() {
   assertEquals(1, 1);
} 
1

In my case, this issue was being caused by Robolectric 4.8, which didn't support targetSdkVersion 33. Upgrading to Robolectric 4.9 solved the issue. I was able to notice the issue by running the test on the test class instead of the method, which gave the targetSdkVersion=33 > maxSdkVersion=32 error message.

0

I faced this error today in one of our projects. After a couple of moments of trying to figure out what was happened, I saw that in my case the problem was the JUnit version that I was using. After migrating to JUnit version '5.8.1' all of my tests stop running, so I did a roll back to version 5.3.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.