简体   繁体   English

Gradle android插件和android测试?

[英]Gradle android plug-in and android tests?

I've written a couple android apps but haven't worked written any android unit tests before.我已经编写了几个 android 应用程序,但之前没有编写任何 android 单元测试。 Now I'm trying to work on what is a bit more of a significant app (at least to me) and I want to use gradle to build it and I'd like to also do it properly and write unit tests and use emma to generate coverage reports.现在我正在尝试开发更重要的应用程序(至少对我来说),我想使用 gradle 来构建它,我也想正确地完成它并编写单元测试并使用 emma生成覆盖率报告。

What's the best way to get started?最好的开始方式是什么? should I generate the project/test project inside eclipse and then create the gradle build afterwards?我应该在 eclipse 中生成项目/测试项目,然后再创建 gradle 构建吗? or should try creating both projects from the command line and importing them into Eclipse?或者应该尝试从命令行创建两个项目并将它们导入 Eclipse? I've had some success doing that with out creating a test project.在没有创建测试项目的情况下,我已经取得了一些成功。

Anyone have a sample build.gradle file that runs android unit tests?有人有运行 android 单元测试的示例 build.gradle 文件吗? bonus points if it is also running emma code coverage.如果它还运行 emma 代码覆盖率,则可以加分。

I've gotten gradle+emma working with a plain old java project with unit tests, but I'm a unsure on how to structure the android project + test cases.我已经让 gradle+emma 使用带有单元测试的普通旧 java 项目,但我不确定如何构建 android 项目 + 测试用例。

Standard Android SDK Tools r15 provides everything you need.标准Android SDK 工具 r15提供您需要的一切。 Here are quick steps:以下是快速步骤:

  1. Create the Android project创建 Android 项目

    $ android create project --target "android-9" --name MyAndroidApp --path./MyAndroidApp --activity MyAndroidAppActivity --package com.example.myandroid $ android 创建项目 --target "android-9" --name MyAndroidApp --path./MyAndroidApp --activity MyAndroidAppActivity --package com.example.myandroid

  2. Create the Android test project创建Android测试工程

    $ android create test-project --main./MyAndroidApp --name MyAndroidAppTest --path./MyAndroidApp/tests $ android 创建测试项目 --main./MyAndroidApp --name MyAndroidAppTest --path./MyAndroidApp/tests

  3. Write your tests编写你的测试

  4. Run your tests (incl. code coverage) from within the Android project从 Android 项目中运行您的测试(包括代码覆盖率)

    $ ant emma debug install test $ ant emma 调试安装测试

  5. View results查看结果

    • test results will be shown in terminal console测试结果将显示在终端控制台中
    • code coverage report will be in coverage/coverage.html代码覆盖率报告将在coverage/coverage.html

Although Gradle is not required for what you seek, you can import the ant targets easily enough and run using gradle:虽然 Gradle 不是您所寻求的,但您可以轻松导入 ant 目标并使用 gradle 运行:

build.gradle build.gradle

ant.importBuild 'build.xml'

... and run it using ...并使用运行它

$ gradle -i emma debug install test

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

相关问题 我的android项目是“使用旧版本的Android Gradle插件” - My android project is “using an old version of the Android Gradle plug-in” Android Studio错误:不支持的Android Gradle插件版本(0.9.2) - Android Studio Error : Unsupported version of the Android Gradle plug-in (0.9.2) Android插件 - Android plug-in 错误:项目使用了不受支持的 Android Gradle 插件版本 (0.12.2) - Error:The project is using an unsupported version of the Android Gradle plug-in (0.12.2) Android源代码插件 - Android Source Code Plug-in Android应用程序插件架构 - Android application plug-in architecture Android Studio:无法在build.gradle文件中找到对Android Gradle插件的任何引用 - Android Studio : Unable to find any references to the Android Gradle plug-in in build.gradle files Gradle同步失败:该项目正在使用不受支持的Android Gradle插件版本(0.12.2)。 推荐的版本是1.5.0 - Gradle sync failed: The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.5.0 错误:该项目正在使用不受支持的Android Gradle插件版本(0.12.2)。 推荐的版本是2.1.0 - Error:The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 2.1.0 Android应用程式上有关于海拔的一些外挂程式吗 - Is There Some Plug-In About Altitude on Android App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM