No tests found for given includes Error, when running Parameterized Unit test in Android Studio
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
“No tests found for given includes” usually means Android Studio launched Gradle with a filter that did not match any discoverable test method. With parameterized tests, the problem is often a mismatch between the JUnit version, the test runner, the source set, or the run configuration that Android Studio generated. The fix is to make sure the parameterized test is written for the runner your module is actually using.
Start with the Correct Test Type
For local JVM unit tests, the file belongs in app/src/test/java or app/src/test/kotlin. For instrumentation tests that run on a device or emulator, it belongs in app/src/androidTest/....
A JUnit 4 parameterized local unit test in Kotlin looks like this:
This requires JUnit 4 on the unit-test classpath.
Check Dependencies and Runner Assumptions
For the example above, your module should include JUnit 4:
If the project uses JUnit 5, the setup is different. Mixing JUnit 4 annotations with a JUnit 5 engine or vice versa is a common reason tests are not discovered.
If you are in androidTest, then @RunWith(Parameterized::class) for a plain local JVM runner may not match the instrumentation setup you expected.
Android Studio Run Configurations Can Go Stale
Sometimes the code is correct, but Android Studio cached a run configuration that filters to a method name or old class signature that no longer exists. Deleting the run configuration and running the test class again from the gutter often fixes it.
Another reliable check is to run the Gradle task directly:
If Gradle finds the test but Android Studio does not, the IDE configuration is usually the problem.
Verify the Test Method Signature
In Java-based JUnit 4 tests, the test method should be public, return void, and be annotated with @Test. Kotlin is less verbose here, but the method still needs to be discoverable by the runner. A parameterized class with no valid test method will also surface as a “no tests found” style failure.
Parameterized Tests Need Discoverable Structure
Make sure:
- the test class is not abstract
- the test method is annotated with
@Test - the parameter provider is valid for the JUnit version in use
- the file sits in the correct source set
- the module dependency includes the right test library
A small mismatch in any of those pieces can lead to a discovery failure that shows up as “no tests found.”
Common Pitfalls
- Writing a JUnit 4 parameterized test while the project is configured for JUnit 5 only.
- Putting a local unit test under
androidTestinstead oftest. - Using a stale Android Studio run configuration with outdated filters.
- Forgetting
@RunWith(Parameterized::class)for a JUnit 4 parameterized class. - Expecting instrumentation runners and local JVM test runners to behave the same way.
Summary
- The error usually means the test runner could not discover any matching test.
- Verify the source set, JUnit version, and parameterized runner all match.
- Use JUnit 4 setup for
@RunWith(Parameterized::class)tests. - Run the test from Gradle to separate IDE issues from test-framework issues.
- If Android Studio still fails, recreate the run configuration.
Related reading
- No valid 'aps-environment' entitlement string found for application on app store
- No version of NDK matched the requested version
- NoClassDefFoundError - Eclipse and Android
- NoClassDefFoundError android.support.v7.internal.view.menu.MenuBuilder
- Normalize data before or after split of training and testing data?
- nosetests with tensorflow lots of debugging output, how to disable
- No variable to save error in Tensorflow
- NoBrokersAvailable NoBrokersAvailable-Kafka Error
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.