Run all unit tests in Android Studio

陌路散爱 提交于 2019-12-03 18:00:23

问题


I have this project in Android Studio :

I wish to run all unit tests in all project with one click.

How i can do it ?


回答1:


First, you can list all the test tasks available in your project with

./gradlew tasks

Then you can choose the tasks you want to execute. If you want to execute all tests for all flavors ans all buildTypes, you just have to run

./gradlew test connectedAndroidTest

If you don't want to remember all the gradle test command each time you want to run the tests, you can create a file "custom_tasks.gradle" and add

task testAll(dependsOn: ['test', 'connectedAndroidTest']) {
   group = 'custom_tasks'
   description = "Run all tests"
}

Then, you just have to run

./gradlew testAll



回答2:


Not sure what version of Android Studio this was added in, but I'm using Android Studio 3.4.

In the Project Explorer Window, select the Project View.

Right click on your root project and select "Create 'All Tests'..."

...this window will appear (these defaults need to be changed)

Change the following options:

  • Search for tests:

    • In whole project
  • JRE:

    • Most recent version of Android API __ Platform that you have available in this menu (for me, Android API 28 Platform
  • Click Apply

  • Select "All Tests" from the drop down menu

  • View output from all your tests




回答3:


  1. In "Project" panel (CMD+1 to show) Right click on "java".
  2. Click "Run tests in Java



回答4:


You can try to use this command line on the android terminal: Mac:

./gradlew test connectedAndroidTest

Windows:

gradlew test connectedAndroidTest



回答5:


If the question is about running by the android studio test runner.. No it's not possible, still now, as I write this but you can have gradle test task in run configurations and run them just by pressing button.

You can open gradle side panel, open root project tasks and find test task in verification task folder and click it. You can also assign shortcut to it or save it to run configurations. Still this will run it in Run panel as gradle task.

(I was looking for a way how to run all tests from inside of android test runner, not command line or gradle task but found out this)



来源:https://stackoverflow.com/questions/41116767/run-all-unit-tests-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!