Missing Run Test in Android Studio

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

This article was originally published at vtsen.hashnode.dev on March 28, 2022.

I noticed in Android Studio Bumblebee, we can’t Run Test anymore from the An…


This content originally appeared on DEV Community and was authored by Vincent Tsen

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

This article was originally published at vtsen.hashnode.dev on March 28, 2022.

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
  • Add this Arguments
--tests "com.example.myapplication.ExampleUnitTest"

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.*"
  • 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"

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"

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

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.

See Also


This content originally appeared on DEV Community and was authored by Vincent Tsen


Print Share Comment Cite Upload Translate Updates
APA

Vincent Tsen | Sciencx (2022-06-18T01:10:01+00:00) Missing Run Test in Android Studio. Retrieved from https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/

MLA
" » Missing Run Test in Android Studio." Vincent Tsen | Sciencx - Saturday June 18, 2022, https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/
HARVARD
Vincent Tsen | Sciencx Saturday June 18, 2022 » Missing Run Test in Android Studio., viewed ,<https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/>
VANCOUVER
Vincent Tsen | Sciencx - » Missing Run Test in Android Studio. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/
CHICAGO
" » Missing Run Test in Android Studio." Vincent Tsen | Sciencx - Accessed . https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/
IEEE
" » Missing Run Test in Android Studio." Vincent Tsen | Sciencx [Online]. Available: https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/. [Accessed: ]
rf:citation
» Missing Run Test in Android Studio | Vincent Tsen | Sciencx | https://www.scien.cx/2022/06/18/missing-run-test-in-android-studio/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.