18

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:

  • go to Project view
    • navigate to ${app}/src/androidTest/java/
    • right-click that node and select Run 'All Tests'
    • select my device
    • run instrumented tests

then

  • go to Project view
    • navigate to ${app}/src/androidTest/java/${package}
    • right-click that node and select Run 'Tests in ${package}'
    • run unit tests

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?

mnagel
  • 6,729
  • 4
  • 31
  • 66

3 Answers3

6

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

Andrew G
  • 663
  • 8
  • 15
  • 3
    The above answer works if you only have one module. If you have multiple modules and want to run all of your tests for all modules in that project, check out my answer: https://stackoverflow.com/a/56192783/2441420 – technoplato May 17 '19 at 20:05
  • this sucks. The root principle of TDD editing is you run _all_ tests with _one_ button. Not "different tests because..." – Phlip Sep 08 '21 at 19:53
1

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

Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
0

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

ryanholden8
  • 536
  • 4
  • 13
  • Is this multi module or single module as see you select a module for instrumented test but i have like 20 modules in project – Renetik Apr 22 '23 at 12:52