3

我们在使用 CPsuite 和 JMockit 运行单元测试时遇到问题。

测试在 Eclipse 中执行时运行良好,但如果我们使用 Ant 脚本运行所有测试(请参阅本问题末尾的脚本),我们会得到以下异常:

Testcase: initializationError took 0 sec
    Caused an ERROR
(class: mockit/internal/startup/JDK6AgentLoader, method: getVirtualMachineImplementationFromEmbeddedOnes signature: ()Lcom/sun/tools/attach/VirtualMachine;) Wrong return type in function
java.lang.VerifyError: (class: mockit/internal/startup/JDK6AgentLoader, method: getVirtualMachineImplementationFromEmbeddedOnes signature: ()Lcom/sun/tools/attach/VirtualMachine;) Wrong return type in function
    at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
    at mockit.internal.startup.Startup.verifyInitialization(Startup.java:86)
    at mockit.Invocations.<clinit>(Invocations.java:22)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

这只发生在 Ant 上,并且只有在 CPSuite 集中有一个使用 JMockit 的类时才会发生。

有谁知道我们为什么会收到这个错误?

蚂蚁脚本:

<project name="chughtai.junit" default="run" basedir=".">

    <taskdef resource="net/sf/antcontrib/antlib.xml"/>

    <!-- https://junit-anttask.dev.java.net/ -->
    <!--
    <taskdef name="junit2" classname="com.sun.ant.junit.JUnitTask">
        <classpath>
            <pathelement path="lib/junit-anttask.jar" />
            <pathelement path="lib/junit-4.4.jar" />
        </classpath>
    </taskdef>
    -->
    <property environment="env"/>

    <property file="junit.build.properties"/>

    <filelist id="third-party_jars" dir="lib">
        <file name="${ext.classpath}/bin/lib/j2ee.jar"/>
    </filelist>

    <path id="project.path">
      <pathelement path="${env.JAVA_HOME}/lib/tools.jar"/>
      <pathelement location="classes/"/>
      <fileset dir="lib">
        <include name="**/*.jar"/>
        <include name="**/*.properties"/>       
      </fileset>
      <dirset dir="${build.dir}">
        <include name="apps/**/classes"/>
        <exclude name="apps/**/*Test*"/>
      </dirset>
      <pathelement location="${basedir}/junittestcases"/>     
      <filelist refid="third-party_jars"/>
      <pathelement path="${ext.classpath}"/>
      <pathelement location="${ext.classpath}/WEB-INF/classes"/>      
    </path>

    <target name="init">
        <mkdir dir="${prd.junit.test.report.dir}" />
        <mkdir dir="${prd.junit.test.report.dir}/html" />
    </target>

    <!-- default target -->
    <target name="run" depends="init">
        <property name="myclasspath" refid="project.path"/>
        <property name="java.class.path" refid="project.path"/>

        <echo message="***Junit Controller Application***"/>    
        <echo message="basedir is ${basedir}"/> 
        <!--<echo message="${myclasspath}" />-->

    <junit dir="${basedir}/junittestcases/" printsummary="yes" haltonfailure="no" fork="no" forkmode="once" reloading="false" maxmemory="1024m">
        <jvmarg value="-Xms768M"/>
        <jvmarg value="-Xmx1024M"/>     
        <jvmarg value="-XX:MaxPermSize=256M"/>
        <sysproperty key="tests" value="${tests}"/>
        <sysproperty key="java.class.path" value="${myclasspath}"/>
        <formatter type="plain" usefile="true" extension=".txt" />
        <formatter type="xml" />
        <classpath refid="project.path"/>

        <test name="${use.testcase}" haltonfailure="no" fork="false" todir="${prd.junit.test.report.dir}" if="use.testcase">
            <formatter type="xml" />
        </test>



    </junit>
        <!--  Generate the Unit Test reports -->

    <junitreport todir="${prd.junit.test.report.dir}">
      <fileset dir="${prd.junit.test.report.dir}">
        <include name="*.xml" />
      </fileset>
      <report todir="${prd.junit.test.report.dir}/html"  styledir="${xsl.templates}" format="frames"> 
        <param name="build.number" expression="${app.build}" />
        <param name="application.name" expression="${app.name}" />
      </report>
    </junitreport>

    </target>

    <target name="emma.report" depends ="" description="Creates 3 EMMA report formats based on the coverage data gathered.">
        <if>
            <available file="coverage.ec" />
            <then>
                <move file="coverage.ec" tofile="${coverage.dir}/junits.ec" overwrite="true"/>
            </then>     
        </if>

        <emma>
            <report sourcepath="src" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
                <!-- collect all EMMA data dumps (metadata and runtime)
                 [this can be done via nested <fileset> fileset elements
                 or <file> elements pointing to a single file]:
                -->

                <fileset dir="${coverage.dir}">
                    <include name="*.em" />
                    <include name="*.ec" />
                </fileset>

                <!-- for every type of report desired, configure a nested
                 element; various report parameters
                 can be inherited from the parent <report>
                 and individually overridden for each report type:
                -->
                <txt outfile="${coverage.dir}/coverage.txt" depth="package" columns="class,method,block,line,name" />
                <xml outfile="${coverage.dir}/coverage.xml" depth="package" />
                <html outfile="${coverage.dir}/coverage.html" depth="method" columns="name,class,method,block,line" />
            </report>
        </emma>

    </target>

    <target name="clean">
        <delete file="${coverage.dir}/coverage.*" />
    </target>
</project>
4

0 回答 0