EMMA for running android application.


▣ 사전지식

본 예제는, test project가 아닌, running application 스스로 EMMA로 instrument해서 coverage를 측정하게 된다.

coverage.em: 이것은 class file들에 대한 meta 정보를 담고 있다.

coverage.em file은 "ant instrument" command를 입력하면, code를 build하며 coverage.em 파일을 생성 하게 된다.



Step 0


GitHub에 있는 Diego의 project를 다운 받는다.

편의를 위해서 본 블로그에 파일을 첨부해 놓았다.

File 1: external library project


ViewServer-master.tar.gz


File 2: Testing App for getting Code Coverage running application with EMMA


TemperatureConverter-master.tar.gz


▣ 기본적으로 Diego의 Project에는 오류가 몇가지 있다.

1) "LocalViewServer" project에 대한 의존성이 있다.

해결 방법: 

GitHub: https://github.com/dtmilano/ViewServer 에서  ViewServer-master를 다운 받는다.

TemperatureConverter-master project의 project.properties를 아래와 같이 수정한다.


android.library.reference.1=../ViewServer-master


2) ViewServer-master에 SDK version이 빠져 있으므로 eclipse에서 추가 해준다.

3) ViewServer-master에 build.xml이 없어서 ant command를 수행 할 수 없다.

해결방법: # android update project -p .



Step 1


root@ubuntu:~/Android_Application_source/TemperatureConverter-master# ant clean

-- clean all class files


Step 2


root@ubuntu:~/Android_Application_source/TemperatureConverter-master# ant instrument install

-- coverage.em 파일이 생성 되어야 한다.


Step 3


This command will start the android application on the device and create coverage.ec file for us


root@ubuntu:~/Android_Application_source/TemperatureConverter-master# adb shell am instrument -e coverage true -w com.example.i2at.tc/com.example.instrumentation.EmmaInstrumentation


-- Block while user action


INSTRUMENTATION_CODE: -1


08-25 21:26:28.245: I/System.out(2102): EMMA: runtime coverage data written to [/mnt/sdcard/coverage.ec] {in 72 ms}


Step 4


/sdcard/coverage.ec 에 위치한것을 꺼내온다.


root@ubuntu:~/Android_Application_source/TemperatureConverter-master/bin# adb pull /sdcard/coverage.ec .
30 KB/s (1202 bytes in 0.038s)


Step 5


▣ 소스코드를 참고하지 않는 경우. // 소스코드를 보지 못함

root@ubuntu:~/Android_Application_source/TemperatureConverter-master/bin# java -cp ~/Android_Application_tools/android-sdk-linux/tools/lib/emma.jar emma report -r html -in coverage.em,coverage.ec


EMMA: processing input files ...
EMMA: 2 file(s) read and merged in 9 ms
EMMA: writing [html] report to [/root/Android_Application_source/TemperatureConverter-master/bin/coverage/index.html] ...


▣ 소스코드를 참고하는 경우. // 소스코드를 볼 수 있음 (방법 아직 모름, ant emma debug install test시 정상적으로 잘 보임)


this command will give html coverage reports, and we can also see the src code also in the html reports.
the -sp option is given for that reason only.
java -cp emma.jar emma report -r html -in coverage.ec -sp D:\xxxxxx\EMMA_Coverage\TemperatureConverter-master\src -in D:\xxxxxx\EMMA_Coverage\TemperatureConverter-master\bin\coverage.em



// 내용 확인

root@ubuntu:~/Android_Application_source/TemperatureConverter-master/bin/coverage# firefox index.html
failed to create drawable


Step 6



결과를 아래와 같이 볼 수 있다. 단, 아직 소스코드 보는 법은 잘 모르겠음.




reference links for both:
-------------------------

key link: http://dtmilano.blogspot.in/2011/11/obtaining-code-coverage-of-running.html


https://developers.google.com/web-toolkit/doc/latest/DevGuideTestingCoverage#command-line

http://primates.ximian.com/~flucifredi/emma-HOWTO.html

http://stackoverflow.com/questions/2762665/how-to-use-emma-code-coverage-in-android

https://groups.google.com/forum/#!topic/android-developers/Q8-KjKVmL4U

http://mebeingneo.wordpress.com/2011/05/19/emma-code-coverage-of-android-2/

+ Recent posts