Android test code coverage, Eclipse

前端 未结 4 873
不知归路
不知归路 2020-12-06 16:28

Is there a way to run unit tests for Android from Eclipse in a way that will instrument the code and measure test code coverage?

I\'m looking for a simple way to fi

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 17:04

    I've been used EMMA (android already support it) for code coverage (and android-junit-report for test reports), here is a summary:

    • Create android project (or library)

    android.bat update project -p project -n my_project -t android-16

    cd project

    ant emma clean debug

    • create a test project (linked to previous library)

    android.bat update project --library ..\project -p project_Test -n project_Test -t

    • in case the main project is not a library

    android.bat update project -m ..\project -p project_Test -n project_Test -t

    ant emma clean debug install I ddidn't use 'test' since I want to run my own instrument

    adb shell am instrument -e coverage true -e coverageFile sdcard/coverage.ec -w com..myproject.test/com.zutubi.android.junitreport.JUnitReportTestRunner

    • Pull files from device (emulator)

    adb pull sdcard/junit-report.xml

    adb pull sdcard/coverage.ec

    • Generate XML report (can also generate html report)

    java -cp emma.jar emma report -r xml -in bin/coverage.em,coverage.ec

    • Generate HTML report (can also generate html report)

    java -cp emma.jar emma report -r html -in bin/coverage.em,coverage.ec

    • Using Post-builds (Jenkins):

      • JUnit report XML
      • Emma Coverage report (give the coverage.xml as input)

    Don't need the emma.jar into libs

    Check it out from my blog

提交回复
热议问题