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 を使用するクラスがある場合にのみ発生します。

なぜこのエラーが発生するのか知っている人はいますか?

Ant スクリプト:

<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