简体   繁体   English

如何在 Android Studio 中一键运行所有(单元和检测)测试

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

I am developing an Android app in Android Studio.我正在 Android Studio 中开发一个 Android 应用程序。 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 go转项目查看
    • navigate to ${app}/src/androidTest/java/导航到${app}/src/androidTest/java/
    • right-click that node and select Run 'All Tests'右键单击该节点和 select Run 'All Tests'
    • select my device select 我的设备
    • run instrumented tests运行仪器测试

then然后

  • go to Project view go转项目查看
    • navigate to ${app}/src/androidTest/java/${package}导航到${app}/src/androidTest/java/${package}
    • right-click that node and select Run 'Tests in ${package}'右键单击该节点和 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.我真正想要的是一个大的绿色按钮,它运行所有测试并一起报告单元测试和仪器测试的 OK/FAILED 结果。 How can I do that?我怎样才能做到这一点?

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 转到项目文件,然后右键单击../app/src/androidTest/java 进行所有仪器化测试

  2. Then right click on ../app/src/test/java 然后右键单击../app/src/test/java 进行所有单元测试

  3. Enjoy! 请享用! =) =)

像这样

Use this way for all modules in a project.对项目中的所有模块使用这种方式。

1.Select Edit Configurations from Android Stduio 1.Select 编辑来自 Android Stduio 的配置

在此处输入图像描述

2.Add Gradle task 2.增加Gradle任务

在此处输入图像描述

3. Set this config 3.设置这个配置

cleanTestDebugUnitTest testDebugUnitTest cleanTestDebugUnitTest 测试DebugUnitTest

--tests "*" --测试“*”

在此处输入图像描述

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM