簡體   English   中英

從Emma代碼覆蓋率報告中過濾junit測試類

[英]Filtering junit test classes from Emma Code Coverage Report

我有一個項目,其中有emma代碼覆蓋率腳本(使用ant)構建並正確生成測試。

我有兩個軟件包com.myproject.abc test.com.myproject.abc

所有的junit測試都在test.com.mywebsite.abc包中。 我的目標是不要在報告(coverage.xml)中包含test.com.myproject.abc包。 我已經閱讀了有關coverage篩選器的emma文檔,並查看了其他幾個示例,但是如果不將junit測試包含在工具中,就無法使其正常工作。

如果我將過濾器包含在檢測目標中,則它不會檢測用於junit測試的junit類。 結果是classNotFoundException。

這是我的代碼。

<target name="emma-instrument" depends="clean" description="instruments the code">   
        <emma enabled="true">  
            <instr instrpath="${classes}" destdir="${emma.instr.dir}"  
                metadatafile="${emma.coverage.dir}/coverage.emma" merge="true" >
                <filter excludes="test.com.myproject.abc"/> 
            </instr>
         </emma>

    </target>  

發生檢測時,它將所有檢測的類移至emma / instrumentation-它包含在類路徑中。

<target name="test" depends="test_preconditions" description="run junit tests">  
        <junit fork="yes" printsummary="yes" haltonfailure="yes">  
            <classpath refid="test.classpath" />  
            <formatter type="plain" usefile="false" />  
            <batchtest>  
                <fileset dir="${classes}">
                    <include name="**/*Test*"/>

                </fileset>
            </batchtest>  
            <jvmarg value="-Demma.coverage.out.file=${emma.coverage.dir}/coverage.emma" />  
            <jvmarg value="-Demma.coverage.out.merge=true" />  
            <jvmarg value="-XX:-UseSplitVerifier"/>
        </junit>  
    </target>  

因此,只需重復一遍-是否可以從Emma Coverage報告中排除JUNIT測試? 我需要更改什么? 提前致謝。

我正在使用Emma 2.1(代碼覆蓋率),java和ant。

您可以像這樣使用JaCoCo庫:

<target name="test" depends="test_preconditions" description="run junit tests">  
    <mkdir dir="${test.data.dir}" />

    <!-- Run all tests -->
    <jacoco:coverage destfile="${test.data.dir}/jacoco.exec">
        <junit fork="yes" printsummary="yes" haltonfailure="yes">  
            <classpath refid="test.classpath" />  
            <formatter type="plain" usefile="false" />  
            <batchtest>  
                <fileset dir="${classes}">
                    <include name="**/*Test*"/>

                </fileset>
            </batchtest>  
        </junit>  
    </jacoco:coverage>

    <!-- Generate Code Coverage report
        See: http://www.eclemma.org/jacoco/trunk/doc/ant.html -->
    <jacoco:report>
        <executiondata>
            <file file="${test.data.dir}/jacoco.exec" />
        </executiondata>

        <structure name="AntTestReporting">
            <classfiles>
                <fileset dir="${build.dir}">
                    <include name="**/*.class" />
                    <!-- Exclude classes necessary for testing only from the code coverage report-->
                    <exclude name="**/*Test*.class" />
                    <!-- Exclude inner classes -->
                    <exclude name="**/*$*.class" />
                </fileset>
            </classfiles>
        </structure>

        <html destdir="${coverage.reports.dir}" />
    </jacoco:report>
</target>

您可以在此處找到更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM