蚂蚁& Concordion:类路径问题

时间:2012-05-31 15:00:14

标签: ant junit classpath concordion

我是Ant / Concordion的新手,也是我关于Stack Overflow的第一个问题,所以希望你能保持温和。

尝试设置Ant任务以自动运行我的Concordion Acceptance Tests并生成摘要/概述/索引html页面,其中列出了传递的测试,失败等等。

我使用的是Concordion Ant Task,但我认为我的类路径不正确。

包结构是镜像test / java / spec& test / resources / spec作为灯具和规格之间的分离。

这是我的build.xml。

<?xml version="1.0" encoding="UTF-8"?>
<project name="Bowling" default="run.acceptance.tests">
    <path id="dependencies">
        <fileset dir="lib" includes="concordion-ant-task-*.jar"/>
        <fileset dir="lib" includes="freemarker*.jar"/>
        <fileset dir="lib" includes="junit*.jar"/>
    </path>

    <taskdef name="junit" 
        classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
    <taskdef name="generate-test-overview"    
        classname="bad.robot.concordion.ant.GenerateTestOverviewTask" 
        classpathref="dependencies"/>

    <target name="check.dependencies"
        unless="classpath.as.supplied.by.maven">
        <!--  <fail message="Missing dependencies, run using Maven instead (*blush*) or switch to use classpathref='dependencies'"/>-->
    </target>

    <target name="generate-overview"
        depends="check.dependencies">
        <generate-test-overview 
            template="src\test\resources\spec\bowlingGame\Overview.ftl"      
            output="src\test\resources\spec\bowlingGame\Overview.html">
            <fileset dir="${basedir}\src\test\resources\spec\bowlingGame\">
                <include name="**/*.html"/>
                <exclude name="**/Overview.html" />
                <exclude name="**/BowlingGame.html" />
            </fileset>
        </generate-test-overview>
    </target>

    <echo message="${basedir}" />

    <target name="run.acceptance.tests"
        depends="generate-overview">
        <junit printsummary="on" haltonfailure="yes">
            <classpath>
                <pathelement location="${basedir}"/>
            </classpath>
            <formatter type="plain"/>
            <test name="Overview"/> <!-- corresponding java fixture, must match the overview page generated -->
        </junit>
    </target>  
</project> 

这是蚂蚁输出。

        Apache Ant version 1.7.1 compiled on June 27 2008
    Using C:\Documents and Settings\gafitzgerald\training\Bowling\ant.log file as build log.
Buildfile: C:\Documents and Settings\gafitzgerald\training\Bowling\build.xml
parsing buildfile C:\Documents and Settings\gafitzgerald\training\Bowling\build.xml with URI = file:/C:/Documents%20and%20Settings/gafitzgerald/training/Bowling/build.xml
Project base dir set to: C:\Documents and Settings\gafitzgerald\training\Bowling
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
     [echo] C:\Documents and Settings\gafitzgerald\training\Bowling
Build sequence for target(s) `run.acceptance.tests' is [check.dependencies, generate-overview, run.acceptance.tests]
Complete build sequence is [check.dependencies, generate-overview, run.acceptance.tests, ]
check.dependencies:
generate-overview:
[generate-test-overview] looking for files in C:\Documents and Settings\gafitzgerald\training\Bowling\src\test\resources\spec\bowlingGame...
[generate-test-overview]    scoring\Scoring.html
[generate-test-overview]    scoring\Spare.html
run.acceptance.tests:

修剪

[junit] Implicitly adding C:\Documents and Settings\gafitzgerald\training\lib\junit-4.8.2.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar to CLASSPATH
    [junit] Using CLASSPATH C:\Documents and Settings\gafitzgerald\training\Bowling;C:\Documents and Settings\gafitzgerald\training\lib\junit-4.8.2.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-launcher.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar;C:\java\eclipse-helios\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-junit.jar
    [junit] Running Overview
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

BUILD FAILED
C:\Documents and Settings\gafitzgerald\training\Bowling\build.xml:31: Test Overview failed
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.actOnTestResult(JUnitTask.java:1840)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:837)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)

1 个答案:

答案 0 :(得分:0)

我重新格式化了您的Ant文件,因此更容易阅读。

我注意到了一些事情:

  • 您不必通过<taskdef> 定义 JUnit任务。 <junit>任务是Ant的一部分。我认为这就是你得到的原因:[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
  • 您需要先编译JUnit测试,然后才能运行它们。这是<generate-test-overview>任务吗?通常,在编译JUnit测试时,应该包含在类路径中:
    • 编译时使用的所有jar。
    • 您构建的JUnit测试将运行的类。
    • junit jar的位置(ant-junt.jar已经在类路径中)。
  • Fork JUnit在运行它们时进行测试。我不知道为什么fork设置为false,但JUnit测试应该分叉。
  • name子实体的<test>参数应该是您要执行的类的名称。我不认为Overview是它。
  • 不要在失败时停止JUnit测试。一次测试可能会失败,但其他测试可能会成功。