0

我一直在为我的 ant 脚本 for emma/junit阅读本教程,它指出

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

这是我的 Apache Ant 的 build.xml 中的 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>

构建部分结果emmaJUNIT 失败结果,指向${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 Pass Result,指向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 测试AppenderLayoutTest在 emma 上失败但在 junit 上通过了。我也很有信心我coverage file没有被创建,因为 JUNIT forAppenderLayoutTest失败了。

我是否使用错误的类集进行测试?还是我错过了什么?

更新: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>

以及更新的构建部分结果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

我添加了<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

4

2 回答 2

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在测试中添加一些内容,看看测试中出了什么问题。这可能与我感觉的配置有关。

于 2012-08-29T06:18:45.257 回答
1

查看您共享的最新跟踪似乎可以使用

-XX:-UseSplitVerifier

作为VM参数来摆脱与JDK7相关的错误。

检查一下

于 2012-08-29T07:13:53.657 回答