一. 用ant, 通过修改build.xml来执行 1. 首先编译test project,注意,如果没有release key,只能编译 debug版本(在eclipse下会用自签名的key签名)2. 执行ant -p,列出可执行的target选项。到底有哪些target, 由build.xml中说明来决定的 <!-- Required pre-setup import --> <import file="${sdk.dir}/tools/ant/pre_setup.xml" />
3. 然后用ant targetname, 做相应的事情 eg. ant debug: Builds the application and signs it with a debug key. ant coverage:Runs the tests against the instrumented code and generates code coverage report ant run-tests: Runs tests from the package defined in test.package property 4. ant coverage 可以 生成html报表,但必须在emulaotr上跑才能生成,在device上跑不能生成
二. 用adb shell am instrument命令来执行 需要借助com.zutubi.android.junitreport.JUnitReportTestRunner The runner supports two arguments: * reportFilePath: the path, relative to the root of the tested application's file storage area, of the report file to generate. Defaults to junit-report.xml. * filterTraces: if true, stack traces in the report will be filtered to remove common noise (e.g. framework methods). Defaults to true. 命令格式为: adb shell am instrument -w -e reportFilePath my-report.xml \ com.example.test/com.zutubi.android.junitreport.JUnitReportTestRunner |