DEV Community

Cover image for Missing Run Test in Android Studio
Vincent Tsen
Vincent Tsen

Posted on • Updated on • Originally published at vtsen.hashnode.dev

Missing Run Test in Android Studio

Manually edit run configuration as workaround for missing run test in Android Studio Bumblebee

I noticed in Android Studio Bumblebee, we can't Run Test anymore from the Android Studio UI. It seems like is a known issue here and supposes it should be fixed in this version already, but somehow I still have the issue?

Expected Behavior

  • From the source code editor Missing_Run_Test_in_Android_Studio_BumbleBee_01.gif
  • From right click folder / file Missing_Run_Test_in_Android_Studio_BumbleBee_02.gif

Android Studio Bumblebee

  • From the source code editor, it shows Nothing here Missing_Run_Test_in_Android_Studio_BumbleBee_03.gif
  • From right click folder / file, Run Tests... menu is not there Missing_Run_Test_in_Android_Studio_BumbleBee_04.gif

Workarounds

I'm not a unit testing guy. Maybe I'm missing something here because it seems like no one complains about this? Anyway, these are the workarounds based on my limited knowledge in testing.

1. Use Different Android Studio Version

I guess you can roll back to previous stable release version Arctic Fox or upgrade to the latest preview version. I personally try Android Studio Dolphin (Canary build preview version) and have no issues.

2. Manually Edit Run Configuration

  • Go to app->Edit Configuration... Missing_Run_Test_in_Android_Studio_BumbleBee_05.gif
  • Add Gradle task
  • Give the gradle task name (any name) and specify the gradle project (based on your project folder name)
  • Add this Task
:app:testDebugUnitTest
Enter fullscreen mode Exit fullscreen mode
  • Add this Arguments
--tests "com.example.myapplication.ExampleUnitTest"
Enter fullscreen mode Exit fullscreen mode

This run all test functions in ExampleUnitTest. If you want to run all classes within the package, you can use the *

--tests "com.example.myapplication.*"
Enter fullscreen mode Exit fullscreen mode
  • So it looks like this
    Missing_Run_Test_in_Android_Studio_BumbleBee_06.png

  • Run the unit test
    Missing_Run_Test_in_Android_Studio_BumbleBee_07.gif

To run unit test in command line, you can run the following command in the terminal

gradlew :app:testDebugUnitTest --tests "com.example.myapplication.ExampleUnitTest"
Enter fullscreen mode Exit fullscreen mode

To run specific unit test function (e.g. ExampleUnitTest.addition_isCorrect), you just need to update the task to

:app:testDebugUnitTest --tests "com.example.myapplication.ExampleUnitTest.addition_isCorrect"
Enter fullscreen mode Exit fullscreen mode

For instrument test, you also need to manually add it, similar to the unit test run configuration above.

  • Go to app->Edit Configuration...
  • Add Android Instrumented Tests
  • Select ** All in Package**
  • Select Module and Package
  • So it looks like this Missing_Run_Test_in_Android_Studio_BumbleBee_08.png
  • Run the instrumented test (similar to the unit test above)

The above steps run all instrumented tests under the specify package. If you want to run test in specify class, just choose Class instead of All in Package and specify the class name you want to run.

To run instrumented test in command line, you can run the following command in the terminal

gradlew :app:connectedDebugAndroidTest
Enter fullscreen mode Exit fullscreen mode

Conclusion

I feel troublesome to manually add the run configuration, especially I want to run a single test that is newly added. Maybe I should just move up my Android Studio version to the latest preview build to get rid of this problem.


Originally published at https://vtsen.hashnode.dev.

Top comments (0)