'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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1