快乐着飞舞着

---Nothing to do is doing nothing
随笔 - 93, 文章 - 5, 评论 - 56, 引用 - 0
数据加载中……

How to do android emma coverage test in your own ant scipts

1.  emma taskdef    <!-- Emma configuration -->
    <property name="emma.dir" value="${android.sdk.root}/tools/lib" />
    
<path id="emma.lib.dir">
        
<pathelement location="${emma.dir}/emma.jar" />
        
<pathelement location="${emma.dir}/emma_ant.jar" />
    
</path>
    
<taskdef resource="emma_ant.properties" classpathref="emma.lib.dir" />
    
<!-- End of emma configuration -->

2.     <!-- - - - - - - - - - - - - - - - - - 
          target: emma-instrument                      
         - - - - - - - - - - - - - - - - - 
-->
    
<target name="emma.instrument" if="enable.emma.on.test">
        
<property name="emma.enabled" value="true" />
        
<echo>Instrumenting classes from ${project.base.dir}/${android.project.dir}/bin,${project.base.dir}/${android.project.dir}/libs/sup-client.jar</echo>
        
<!-- It only instruments class files, not any external libs -->
        
<emma enabled="${emma.enabled}">
            
<instr mode="overwrite"
                   instrpath
="${project.base.dir}/${android.project.dir}/bin,${project.base.dir}/${android.project.dir}/libs/sup-client.jar"
                   outdir
="${project.base.dir}/${android.project.dir}/bin">
            
</instr>
            
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
                         user defined file 
-->
        
</emma>
        
<echo>Copy emma. to project libs</echo>
        
<copy todir="${project.base.dir}/${android.project.dir}/libs" overwrite="true">
             
<fileset dir="${emma.dir}" includes="emma_device.jar"/>
        
</copy>
        
    
</target>
333
    <!-- Convert this project's .class files into .dex files. -->
    
<target name="dex" depends="android-javac">
        
<antcall target="emma.instrument"></antcall>
        
<condition property="dx.extra.args" value="--no-locals" else="">
            
<istrue value="${enable.emma.on.test}"/>
        
</condition>
        
<echo>Converting compiled files and external libraries into dex file </echo>
        
<apply executable="${dx}" failonerror="true" parallel="true">
            
<arg value="--dex" />
            
<arg value="${dx.extra.args}" />
            
<arg value="--output=${project.base.dir}/${android.project.dir}/bin/classes.dex" />
            
<arg path="${project.base.dir}/${android.project.dir}/bin" />
            
<fileset dir="${project.base.dir}/${android.project.dir}/libs">
                
<include name="**/*.jar"/>
            
</fileset>
        
</apply>
    
</target>


44

<target name="run-tests"
                description
="Runs tests from the package defined in test.package property">
        
<property name="reports.dir" value="${reports.out.dir}/reports"/>
        
<property name="device.reports.dir" value="/data/data/${manifest.package}/files/reports/"/>
        
<echo>Running tests</echo>
        
<exec executable="${adb}" failonerror="true">
            
<arg value="shell" />
            
<arg value="am" />
            
<arg value="instrument" />
            
<arg value="-w" />
            
<arg value="-e" />
            
<arg value="coverage" />
            
<arg value="true" />
            
<arg value="-e" />
            
<arg value="coverageFile" />
            
<arg value="${device.reports.dir}coverage.ec" />
            
<arg value="-e" />
            
<arg value="junitOutputDirectory" />
            
<arg value="${device.reports.dir}" />
            
<arg value="-e" />
            
<arg value="junitSplitLevel" />
            
<arg value="class" />
            
<arg value="-e" />
            
<arg value="package" />
            
<arg value="${test.target.package}" />
            
<arg value="${manifest.package}/${test.runner}" />
        
</exec>

        
<echo>Downloading XML test reports</echo>
        
<mkdir dir="${reports.dir}"/>
        
<exec executable="${adb}" failonerror="true">
            
<arg value="pull" />
            
<arg value="${device.reports.dir}/" />
            
<arg value="${reports.dir}" />
        
</exec>
        
<exec executable="${adb}" failonerror="true">
            
<arg value="pull" />
            
<arg value="${device.reports.dir}/" />
            
<arg value="${reports.dir}" />
        
</exec>
    
</target>

555

        <antcall target="reinstall">
            
<param name="android.project.dir" value="end2end_rdb_mbs"/>
            
<param name="android.app.name" value="end2end_rdb_mbs"/>
            
<param name="project.base.dir" value="${project.home}/android_mbs"/>
            
<param name="enable.emma.on.test" value="true"/>
        
</antcall>

666

        <antcall target="run-tests">
            
<param name="android.project.dir" value="end2end_rdb_mbs"/>
            
<param name="android.app.name" value="end2end_rdb_mbs"/>
            
<param name="project.base.dir" value="${project.home}/android_mbs"/>
            
<param name="manifest.package" value="end2end.test"/>
            
<param name="test.target.package" value="end2end.test.rest.mbs.android"/>
            
<param name="test.runner" value="pl.polidea.instrumentation.PolideaInstrumentationTestRunner"/>
            
<param name="enable.emma.on.test" value="true"/>
        
</antcall>

posted on 2011-06-30 15:59 快乐着飞舞着 阅读(1895) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。

Clicky