6

[Note from the future, 2021, added at the bottom - they shortened the answer]

Below i have a project with the above structure.

I can happily run uni tests fine inside the app module but unit tests found on the lib module doesn't get run unless i manually right click DummyDataTest.java inside the lib module and click run unit test inside Android studio.

Is there a way to automatically run unit tests located in my lib module through command line?

The existing command line ./gradlew testDebug only runs the unit tests located inside the app module.

Thanks in advance

JUnitTestProject
    app [module]
         src
             main
                 java
                     de.ivu.junittest.app
                         DummyModel.java
                         ...
                 ...
             test
                 java
                     de.ivu.junittest.app
                         DummyModelTest.java
                 ...
    lib [module]
         src
             main
                 java
                     de.ivu.junittest
                         DummyData.java
                         ...
                 ...
         test
                 java
                     de.ivu.junittest.app
                         DummyDataTest.java
                 ...
Phlip
  • 5,392
  • 3
  • 29
  • 46
Jonathan
  • 16,547
  • 47
  • 128
  • 211

2 Answers2

3

Yes, use ./gradlew lib:testDebugUnitTest to run tests from lib module.

Uyghur Lives Matter
  • 17,261
  • 40
  • 105
  • 135
vk.4884
  • 445
  • 2
  • 9
  • 1
    Also see my answer here: https://stackoverflow.com/questions/57057053/android-command-line-how-to-run-a-single-unit-test-method/57282139#57282139 if you need to specify a test name. – Mark Han Aug 01 '19 at 21:14
-1

$ ./gradlew lib:testDebugUnitTest

FAILURE: Build failed with an exception.

* What went wrong:
Project 'lib' not found in root project 'Yo'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

$ ./gradlew testDebugUnitTest

Happiness

Phlip
  • 5,392
  • 3
  • 29
  • 46