mnagel
mnagel

Reputation: 6854

how to run all (unit and instrumented) tests with one click in Android Studio

I am developing an Android app in Android Studio. I have unit tests and instrumented tests.

I want to run them all to see if I broke something.

Right now my workflow is:

then

What I am really looking for is a big green button that runs all of the tests and reports back the result of OK/FAILED for both unit and instrumented tests together. How can I do that?

Upvotes: 19

Views: 6712

Answers (3)

ryanholden8
ryanholden8

Reputation: 714

Here's how to make 1 button that runs both all unit tests and instrumentation/UI tests:

Steps

  1. Create a Run Configuration > Gradle > Named: Unit Tests
  2. Create a Run Configuration > Android Instrumentation Tests > Named Unit + UI Tests
  3. For the Unit + UI Tests configuration > Before Launch Option > Add Run Another Configuration > Unit Tests
  4. Run your new Unit + UI Tests configuration. Your Unit tests and UI Tests will both run but they will be in separate tabs, since each tab has specific tooling options.

Same Steps as Above but with pictures:

1. Create a Run Configuration > Gradle > Named: Unit Tests

enter image description here

enter image description here

enter image description here

2. Create a Run Configuration > Android Instrumentation Tests > Named Unit + UI Tests

enter image description here

3. For the Unit + UI Tests configuration > Before Launch Option > Add Run Another Configuration > Select the newly created Unit Tests configuration

enter image description here

enter image description here

4. Run your new Unit + UI Tests. Your Unit tests and UI Tests will both run but they will be in separate tabs, since each tab has specific tooling options.

enter image description here

Upvotes: 0

Rasoul Miri
Rasoul Miri

Reputation: 12222

Use this way for all modules in a project.

1.Select Edit Configurations from Android Stduio

enter image description here

2.Add Gradle task

enter image description here

3. Set this config

cleanTestDebugUnitTest testDebugUnitTest

--tests "*"

enter image description here

Upvotes: 2

Andrew G
Andrew G

Reputation: 689

You cannot start both tests at the same time...

But you can create two big green buttons.

  1. Go to your project files and right click on ../app/src/androidTest/java make all instrumented tests

  2. Then right click on ../app/src/test/java make all unit tests

  3. Enjoy! =)

like this

Upvotes: 7

Related Questions