开发者

Is it possible to simply compile an Emma instrumented APK using Android build.xml and not run any tests

开发者 https://www.devze.com 2023-01-22 19:11 出处:网络
I know of ant coverage However that does a few things, it compiles with emma instrumentation, installs, and runs the test apk. I don\'t want it to run the test suite through ant with coverage beca

I know of

ant coverage

However that does a few things, it compiles with emma instrumentation, installs, and runs the test apk. I don't want it to run the test suite through ant with coverage because I need to run it with some extra hooks, and I don't want to run the large test suite twice. So far I have tried this

Target_Project/build.properties

emma.enabled=true

Test_Project/build.properties

emma.enabled=true

Then in in a shell I execute this.

Target_Project$ ant debug
Target_Project$ adb install bin/Target_Project-debug.apk
Target_Project$ cd ../Test_Project/
Test_Project$ ant debug
Test_Project$ adb install bin/Test_Project-debug.apk
Test_Project$ adb shell am instrument -e coverage true -e coverageFile /sdcard/myFile.ec -w com.my_app.testproject/androi开发者_StackOverflow中文版d.test.InstrumentationTestRunner

The response is

Error: Failed to generate emma coverage. Is emma jar on classpath?

So is there a trick to getting the apk to build with the emma libs? I tried invoking the targets created in the sdk xml templates but they are "private." Is there something I am missing?


Well for anyone interested. The SDK documentation is completely busted (surprising I know). Basically you have to do this,

take the base build.xml generated by android create-project and change the tag

<setup/>

and change it to

<setup import="false"/>

Now the documentation will tell you to copy from SDK/platform-/templates/android_rules.xml and place that into your build.xml ... THIS IS WRONG and horribly unmaintained. This rules file isn't used by anything. What is used are the rules inside of SDK/tools/ant/. Grab the appropriate file for your type of project (library for a library project, test for a test project, or vanilla for a regualr project) with the latest _r and
copy the contents of it's root node into your build.xml. Insert it after the setup tag. If you don't use the files inside the ant directory, you will not be able to compile project libraries through the ant script. I was so glad they maintained documentation on how to do this.

Now you can change whatever you like in the build file to match your build needs. In which case I just made install-helper call my wrapper around adb which returns interpreted resultcodes.


// coverage.py

development\testrunner\coverage.py

def TestDeviceCoverageSupport(adb): """Check if device has support for generating code coverage metrics.

This tries to dump emma help information on device, a response containing help information will indicate that emma is already on system class path.

Returns: True if device can support code coverage. False otherwise. """ try: output = adb.SendShellCommand("exec app_process / emma -h")

if output.find('emma usage:') == 0:
  return True

except errors.AbortError: pass return False

adb shell exec app_process / eamm -h

build core images http://duykham.blogspot.com/2009/09/how-to-get-emma-code-coverage-of.html

0

精彩评论

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