Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run all unit tests in Android Studio

I have this project in Android Studio :

enter image description here

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

How i can do it ?

like image 914
Kevin ABRIOUX Avatar asked Dec 13 '16 08:12

Kevin ABRIOUX


People also ask

What is test folder in Android Studio?

By default, Unit tests are written in src/test/java/ folder and Instrumentation tests are written in src/androidTest/java/ folder. Android studio provides Run context menu for the test classes to run the test written in the selected test classes.


2 Answers

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

Android Studio Version 3.4

In the Project Explorer Window, select the Project View.

Project View Select

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

Create 'All Tests'

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

Default edit config window

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

Edited Test configuration

  • Select "All Tests" from the drop down menu

enter image description here

  • View output from all your tests

enter image description here

like image 72
stack_overflow_user Avatar answered Sep 20 '22 18:09

stack_overflow_user


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 
like image 42
And1 Avatar answered Sep 22 '22 18:09

And1