Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Can not find Run test choice

When I try to run the unit test in a class, I can not find a Run choice enter image description here

But I can see it on my teammate laptop in the same project and when clicking on the arrow beside the function and the class name it displays "Nothing here" enter image description here

like image 759
Mohammad Sommakia Avatar asked Oct 24 '25 05:10

Mohammad Sommakia


1 Answers

Here are some steps you can try to avoid reinstalling android studio, with examples from a project having working instrumented tests.
In general, if you also have a pc where the tests works, I advise you to compare all the following configurations between the two environments. Also try to start the tests with a preview version of Android Studio.

Enable test plugins

Go to Android Studio -> Preferences... -> Plugins and check if the test plugins are enabled (i.e. JUnit)

enter image description here

Update Gradle version

Go to File > Project Structure... > Project and update to the latest Gradle version.

Update Kotlin and Gradle plugin versions

Check if you're using the latest versions in your build.gradle (project level)

classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

Update your test dependencies

In your build.gradle (module level)

android {
    ...
    defaultConfig {
        ...
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dependencies {
    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "androidx.test.ext:junit:1.1.3"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
    ...

Remove JUnit group exclusion

In the same file, if present, remove the following exclusion

exclude group: "org.junit.platform" //remove this line
like image 152
Stefano Sansone Avatar answered Oct 26 '25 17:10

Stefano Sansone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!