[英]Run all unit tests in Android Studio
Not sure what version of Android Studio this was added in, but I'm using Android Studio 3.4 .不确定这是在哪个版本的 Android Studio 中添加的,但我使用的是Android Studio 3.4 。
In the Project Explorer Window, select the Project View .在 Project Explorer 窗口中,选择Project View 。
Right click on your root project and select "Create 'All Tests'..."右键单击您的根项目并选择“创建'所有测试'...”
... this window will appear (these defaults need to be changed) ...将出现此窗口(这些默认值需要更改)
Change the following options:更改以下选项:
Search for tests:搜索测试:
JRE: JRE:
Click Apply点击应用
First, you can list all the test tasks available in your project with首先,您可以列出项目中可用的所有测试任务
./gradlew tasks
Then you can choose the tasks you want to execute.然后您可以选择要执行的任务。 If you want to execute all tests for all flavors ans all buildTypes, you just have to run如果你想为所有风格和所有构建类型执行所有测试,你只需要运行
./gradlew test connectedAndroidTest
If you don't want to remember all the gradle test command each time you want to run the tests, you can create a file "custom_tasks.gradle" and add如果不想在每次运行测试时记住所有 gradle test 命令,可以创建一个文件“custom_tasks.gradle”并添加
task testAll(dependsOn: ['test', 'connectedAndroidTest']) {
group = 'custom_tasks'
description = "Run all tests"
}
Then, you just have to run然后,你只需要运行
./gradlew testAll
You can try to use this command line on the android terminal: Mac:您可以尝试在 android 终端上使用此命令行:Mac:
./gradlew test connectedAndroidTest
Windows:视窗:
gradlew test connectedAndroidTest
Running unit tests with Gradle 使用Gradle运行单元测试
Local unit test 本地单元测试
./gradlew test
./gradlew :<moduleName>:test<variantName>UnitTest --tests <pattern>
Instrumented unit test 仪表单元测试
./gradlew connectedAndroidTest
./gradlew :<moduleName>:connected<variantName>AndroidTest -Pandroid.testInstrumentationRunnerArguments.class=<package.TestClassName>
If the question is about running by the android studio test runner.. No it's not possible, still now, as I write this but you can have gradle test task in run configurations and run them just by pressing button. 如果问题是关于由android studio测试运行器运行..不,现在仍然不可能,因为我写这个但你可以在运行配置中进行gradle测试任务,只需按下按钮即可运行它们。
You can open gradle side panel, open root project tasks and find test task in verification task folder and click it. 您可以打开gradle侧面板,打开根项目任务并在验证任务文件夹中找到测试任务并单击它。 You can also assign shortcut to it or save it to run configurations. 您也可以为其指定快捷方式或将其保存为运行配置。 Still this will run it in Run panel as gradle task. 仍然会在运行面板中将其作为gradle任务运行。
(I was looking for a way how to run all tests from inside of android test runner, not command line or gradle task but found out this) (我一直在寻找一种方法如何从android测试运行器内部运行所有测试,而不是命令行或gradle任务,但发现了这一点)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.