小编典典

EMMA with Junit,我应该使用检测类或Java类进行测试吗?

java

我一直在为ema /
junit编写ANT脚本的本教程,它指出

在中的<classpath>元素中<junit>,更改实际类的位置,以便您指向$ {instr.dir}属性,而不是常规的target /
classes文件夹。

这是我的build.xml中关于Apache
Ant的emma部分(pastebin链接到完整的build.xml)

<!-- =================================================================== -->
<!-- Run the tests with EMMA
* depends from  compile                                                                                                                        -->
<!-- =================================================================== -->
<target name="emmatest" depends="compile" description="Tests the project with Emma Query" >
    <!-- ======================================================================= -->
    <!-- EMMA INSTRUMENTATION -->
    <!-- ======================================================================= -->
    <emma enabled="${emma.enabled}" >
        <instr instrpathref="emma.coverage.classes"
             destdir="${instr.dir}"
             metadatafile="${coverage.dir}/metadata.emma"
             merge="true"
             >
            <filter value="${emma.filter}" />
        </instr>
    </emma> 
    <junit fork="true" forkmode="once" >
         <test name="test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest" todir="${coverage.dir}">
          <formatter type="xml"/>
          </test>
         <classpath>
                <path refid="emma.lib" />
                <pathelement location="${instr.dir}"/>
                <fileset dir="${lib.dir}">
                   <include name="**/*.jar"/>
                </fileset>
        </classpath>
         <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
         <jvmarg value="-Demma.coverage.out.merge=false" />
    </junit>
</target>

emma:的 JUNIT失败结果 的生成部分结果 ,指向${instr.dir}

 emmatest:
 [instr] processing instrumentation path ...
 [instr] instrumentation path processed in 109 ms
 [instr] [6 class(es) instrumented, 0 resource(s) copied]
 [instr] metadata merged into [C:\Users\Michael\workspace\log4jassignment.s06005586\build\emma-reports\metadata.emma] {in 42 ms}
 [junit] Test test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest FAILED

生成部分的结果junitreportJUNIT通过结果,指向real classes ${build.classes}

test:
[junit] Running test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.504 sec
[junit] Running test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest
[junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.526 sec

我想知道为什么我的JUNIT Test
AppenderLayoutTest不能通过emma失败,但是通过junit通过。我也非常有信心我coverage file不会被创建,因为JUNIT AppenderLayoutTest失败了。

我是否在测试一组错误的类?还是我错过了什么?

更新:2012年8月28日下午6:21

然后我改变了

<test 
name="test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest"
todir="${coverage.dir}">

<batchtest>
    <fileset dir="${instr.dir}" includes="**/*Test.class" />
</batchtest>

以及更新的Build Section Results for emmaJUNIT Fail
Result,指向${instr.dir}
何处。

emmatest:
[instr] processing instrumentation path ...
[instr] instrumentation path processed in 105 ms
[instr] [6 class(es) instrumented, 0 resource(s) copied]
[instr] metadata merged into [C:\Users\Michael\workspace\log4jassignment.s06005586\build\emma-reports\metadata.emma] {in 89 ms}
[junit] TEST test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest FAILED
[junit] TEST test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest FAILED
[junit] Tests FAILED

更新:7:02 PM

我添加了<formatter type="plain" usefile="false" />,这是输出

emmatest:
[instr] [EMMA v2.1, build 5320 (stable) (2005/06/20 22:08:27)]
[instr] instrumentation path:
[instr] {
[instr]   C:\Users\Michael\workspace\log4jassignment.s06005586\build\classes
[instr] }
[instr] instrumentation output mode: copy
[instr] metadata output file: C:\Users\Michael\workspace\log4jassignment.s06005586\build\emma-reports\metadata.emma
[instr] metadata output merge mode: true
[instr] processing dir path entry [C:\Users\Michael\workspace\log4jassignment.s06005586\build\classes] ...
[instr] instrumentation path processed in 147 ms
[instr] [6 class(es) instrumented, 0 resource(s) copied]
[instr] metadata contains 6 entries
[instr] metadata merged into [C:\Users\Michael\workspace\log4jassignment.s06005586\build\emma-reports\metadata.emma] {in 49 ms}
[junit] Running test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest
[junit] Testsuite: test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]     Caused an ERROR
[junit] Illegal local variable table length 17 in method test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest.<init>()V
[junit] java.lang.ClassFormatError: Illegal local variable table length 17 in method test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest.<init>()V
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Unknown Source)
[junit] TEST test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest FAILED
[junit] Running test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest
[junit] Testsuite: test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit]     Caused an ERROR
[junit] Expecting a stackmap frame at branch target 11 in method test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest.<init>()V at offset 4
[junit] java.lang.VerifyError: Expecting a stackmap frame at branch target 11 in method test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest.<init>()V at offset 4
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Unknown Source)
[junit] TEST test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.StressTest FAILED
[junit] Tests FAILED

什么是 [junit] java.lang.ClassFormatError: Illegal local variable table length 17 in method test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest.<init>()V


阅读 229

收藏
2020-11-30

共1个答案

小编典典

你可以尝试更换

<test 
name="test.nz.ac.massey.cs.sdc.log4jassignment.s06005586.AppenderLayoutTest"
todir="${coverage.dir}">

<batchtest>
    <fileset dir="${instr.dir}" includes="**/*Test.class" />
</batchtest>

最后,我想请您sysout在测试中进行一些测试,看看测试出了什么问题。我觉得这可能与配置有关。

2020-11-30