Kevin ABRIOUX
Kevin ABRIOUX

Reputation: 17695

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 ?

Upvotes: 117

Views: 66712

Answers (8)

fierce_bunny
fierce_bunny

Reputation: 603

In terminal: ./gradlew testDebugUnitTest

Upvotes: 4

Andy Su
Andy Su

Reputation: 11

Open Android Studio Giraffe | 2022.3.1

  1. Open Gradle panel on the right-top side
  2. Project name -> Tasks -> verification -> click "testDebugUnitTest" (Debug is your variants)

Upvotes: 1

ChinLoong
ChinLoong

Reputation: 1833

enter image description here

If you're having issues running the command from cmd. You can run the command in android studio

  1. Click on Gradle on the right side of Android Studio.

  2. Click on "Execute Gradle Task" icon

  3. Type command "gradle test connectedAndroidTest" and enter

Upvotes: 0

Benjamin Mesing
Benjamin Mesing

Reputation: 4305

With AndroidStudio ArcticFox the approach is as follows:

In the toolbar under the run configuration select "Edit Configurations" Menu entry

Select (+) to add a new configuration and choose Gradle:

Add configuration

On the configuration page:

  • give the configuration a Name (Run all unit tests)
  • Choose your root project as Gradle Project
  • add the Tasks cleanTestDebugUnitTest testDebugUnitTest (you can copy that from an existing configuration for unit tests, but make sure to remove the module prefix (e.g. :app:))
  • [Seems like this step is no longer required in latest AS version] add --tests "*" as Arguments (apparently that tells AS to show the results as TestResults)

configuration

Select and run your new configuration. The Results will be shown in the run window: Test run results

Upvotes: 41

technoplato
technoplato

Reputation: 3421

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

Upvotes: 82

Andrii Kovalchuk
Andrii Kovalchuk

Reputation: 4897

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

Upvotes: 22

And1
And1

Reputation: 760

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

Upvotes: 63

Xavier Bauquet
Xavier Bauquet

Reputation: 732

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

./gradlew test connectedAndroidTest

Windows:

gradlew test connectedAndroidTest

Upvotes: 12

Related Questions