开发者

Gradle android plug-in and android tests?

I've written a couple android apps but haven't worked written any android unit tests before. 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.

What's the best way to get started? should I generate the project/test project inside eclipse and then create the gradle build afterwards? or should try开发者_Python百科 creating both projects from the command line and importing them into 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? bonus points if it is also running emma code coverage.

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.


Standard Android SDK Tools r15 provides everything you need. Here are quick steps:

  1. Create the Android project

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

  2. Create the Android test project

    $ android create test-project --main ./MyAndroidApp --name MyAndroidAppTest --path ./MyAndroidApp/tests

  3. Write your tests

  4. Run your tests (incl. code coverage) from within the Android project

    $ ant emma debug install test

  5. View results

    • test results will be shown in terminal console
    • code coverage report will be in coverage/coverage.html

Although Gradle is not required for what you seek, you can import the ant targets easily enough and run using gradle:

build.gradle

ant.importBuild 'build.xml'

... and run it using

$ gradle -i emma debug install test
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜