简体   繁体   English

如何运行位于 android 模块内的单元测试?

[英]How to run unit tests located inside a android module?

[Note from the future, 2021, added at the bottom - they shortened the answer] [来自未来的注意事项,2021,添加在底部 - 他们缩短了答案]

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.我可以愉快地在 app 模块中运行 uni 测试,但是在 lib 模块上找到的单元测试不会运行,除非我手动右键单击 lib 模块中的 DummyDataTest.java 并单击 Android Studio 中的运行单元测试。

Is there a way to automatically run unit tests located in my lib module through command line?有没有办法通过命令行自动运行位于我的 lib 模块中的单元测试?

The existing command line ./gradlew testDebug only runs the unit tests located inside the app module.现有的命令行 ./gradlew testDebug 只运行位于 app 模块内的单元测试。

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
                 ...

是的,使用./gradlew lib:testDebugUnitTest从 lib 模块运行测试。

$ ./gradlew lib:testDebugUnitTest $ ./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幸福

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Android运行单元测试不在设备或模拟器上? - How to run unit tests for Android is not on the device or emulator? 如果我将测试放在单独的模块中,如何在多模块 maven 设置中运行单元测试? - How to run unit tests in multi-module maven setup if i put the tests in a separate module? 如何使 Cucumber 功能在 Android 项目中作为本地单元测试运行? - How to make Cucumber features run in an Android project as local unit tests? Android Gradle:如何分别运行集成和单元测试? - Android gradle: how to run separately integration and unit tests? 在使用Android Studio保存时运行单元测试 - Run unit tests on Save with Android Studio 如何在Maven中的排除组中运行单元测试 - How to run unit tests in excludedGroups in Maven 如何运行带有阴影依赖项的单元测试? - How to run unit tests with shaded dependencies? 如何在 Java 中打印内部单元测试? - How to print inside unit tests in Java? 如何通过maven分别运行集成测试和单元测试? - How to make integration tests and unit tests run separately through maven? 在Android项目中使用Java模块进行单元测试有什么意义吗? - Is there any point in using a Java module for unit tests in an Android project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM