No tests found for given includes: [***Test](filter.includeTestsMatching)

Viewed 40324

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```



8 Answers

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.

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")
    }
}

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'

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")

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.

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);
} 

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

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

Related