2

我正在尝试创建一个 ant 脚本来运行 ptest 以便能够自动化我的突变测试。我收到错误消息:

无法找到或加载主类 org.pitest.mutationtest.commandline.MutationCoverageReport

这是我的 MutationTest.xml 蚂蚁脚本

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="mutationCoverage" name="PhoneBook">
    <property name="ECLIPSE_HOME" value="C:/Program Files/eclipse/"/>
    <path id="JUnit 4.libraryclasspath">
        <pathelement location="${ECLIPSE_HOME}plugins/org.junit_4.11.0.v201303080030/junit.jar"/>
        <pathelement location="${ECLIPSE_HOME}plugins/org.hamcrest.core_1.3.0.v201303031735.jar"/>
    </path>
    <path id="PhoneBook.classpath">
        <pathelement location="bin"/>
        <path refid="JUnit 4.libraryclasspath"/>
    </path>
    <path id="pit.path">
        <pathelement location="lib/pitest-1.1.4.jar" />
        <pathelement location="lib/pitest-ant-1.1.4.jar" />
    </path>

    <taskdef name="pitest" classname="org.pitest.ant.PitestTask" classpathref="pit.path" />

    <target name="mutationCoverage">
        <pitest
            pitClasspath="PhoneBook.path"
            classPath="PhoneBook.path"
            targetClasses="pbook.*"
            targetTests="pbook.*"
            reportDir="MutationReports"
            sourceDir="src"/>
    </target>
</project>

是什么导致了这个错误,我该如何解决?

编辑:我改为pitClasspath="PhoneBook.path"现在pitClasspath="pit.path"我有一个新错误:

[pitest] Exception in thread "main" org.pitest.util.PitError: Unable to load class content for org.pitest.boot.HotSwapAgent
[pitest] Please copy and paste the information and the complete stacktrace below when reporting an issue
[pitest] VM : Java HotSpot(TM) 64-Bit Server VM
[pitest] Vendor : Oracle Corporation
[pitest] Version : 25.25-b02
[pitest] Uptime : 370
[pitest] Input -> 
[pitest] BootClassPathSupported : true
[pitest]    at org.pitest.mutationtest.tooling.JarCreatingJarFinder.classBytes(JarCreatingJarFinder.java:124)
[pitest]    at org.pitest.mutationtest.tooling.JarCreatingJarFinder.addClass(JarCreatingJarFinder.java:113)
[pitest]    at org.pitest.mutationtest.tooling.JarCreatingJarFinder.createJarFromClassPathResources(JarCreatingJarFinder.java:98)
[pitest]    at org.pitest.mutationtest.tooling.JarCreatingJarFinder.createJar(JarCreatingJarFinder.java:74)
[pitest]    at org.pitest.mutationtest.tooling.JarCreatingJarFinder.getJarLocation(JarCreatingJarFinder.java:63)
[pitest]    at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:70)
[pitest]    at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:43)
[pitest]    at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:72)
[pitest]    at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:43)

我不知道这是更好还是更糟,但希望它有助于找到问题。

4

2 回答 2

1

Pitest ant 构建的工作示例提供于

https://github.com/hcoles/pitest-ant-example

我建议你从这个开始并编辑它,直到你的代码库有一个工作版本。

我可以看到的一个区别是您没有将 junit 包含在最糟糕的路径中。

您的构建看起来有点奇怪,因为它似乎与日食有关。如果您从 IDE 运行,为什么不使用 eclipse 插件?

此外,如果您不依赖于 Ant,您可能需要考虑将 maven 作为替代方案。

于 2015-02-19T17:59:26.090 回答
0

我相信您的大部分问题是您正在尝试使用 Eclipse 生成的 build.xml 文件,该文件不包含突变测试目标,并且您为解决此问题而添加的目标有一些错误。

我建议从这里的项目开始并尝试了解它是如何工作的,然后更改他们的 build.xml 文件以满足您的需求。但是,如果这不起作用,从您的其他问题来看,以下 build.xml 应该在以下情况下起作用:

  1. 您将文件分为两个源目录“src”和“test”
  2. src 和 test 文件夹都包含包“pbook”
  3. 您将测试的名称更改为以“Test”结尾而不是开头

<?xml version="1.0" encoding="UTF-8"?>

<project name="Phonebook">

    <property name="classOutputDir" value="build" />

        <!-- classpath for pitest and any plugins -->
    <path id="pitest.path">
                <!-- must currently include the test library on the tool classpath. this will be fixed in a future version-->
           <pathelement location="lib/junit-4.9.jar" />
        <pathelement location="lib/pitest-0.33.jar" />
        <pathelement location="lib/pitest-ant-0.33.jar" />
    </path>

    <taskdef name="pitest" classname="org.pitest.ant.PitestTask" classpathref="pitest.path" />

    <target name="clean">
        <delete dir="${classOutputDir}" />
    </target>

    <target name="compile" depends="clean">
        <mkdir dir="${classOutputDir}/classes" />
        <!-- Essential that line numbers and filenames are included in order for PIT to work -->
        <javac srcdir="src" includeantruntime="false" debug="true" debuglevel="source,lines" destdir="${classOutputDir}/classes" />
    </target>

   <!-- classpath for compiling and testing the code. Note it does not include pitest and it's dependencies -->
    <path id="test.path">
        <pathelement location="${classOutputDir}/classes" />
        <pathelement location="${classOutputDir}/test-classes" />
        <pathelement location="lib/junit-4.9.jar" />
    </path>

    <target name="test" depends="compile">
        <mkdir dir="${classOutputDir}/test-result" />
        <mkdir dir="${classOutputDir}/test-classes" />
        <javac includeantruntime="false" srcdir="test" destdir="${classOutputDir}/test-classes">
            <classpath refid="test.path" />
        </javac>

        <junit>
            <classpath refid="test.path" />
            <batchtest todir="${classOutputDir}/test-result">
                <!-- set test classes -->
                <fileset dir="test">
                    <include name="**/*Test.java" />
                </fileset>
                <formatter type="xml" />
            </batchtest>
        </junit>

        <junitreport todir="${classOutputDir}/test-result">
            <fileset dir="${classOutputDir}/test-result">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="${classOutputDir}/test-result/report" />
        </junitreport>

    </target>
    
    <!-- run pitest. note that the filters for tests and classes refer to package/class names, not source file named -->
    <target name="pit" depends="test">
        <path id="mutation.path">
            <path refid="pitest.path"/>
            <path refid="test.path"/>
        </path>
        <pitest pitClasspath="pitest.path" threads="2" classPath="mutation.path" targetTests="pbook.*" targetClasses="pbook.*" reportDir="pitReports" sourceDir="src" />
    </target>

</project>

于 2015-02-20T05:10:48.343 回答