2012-05-31 114 views
0

我是Ant/Concordion的新手,我的第一個問題是堆棧溢出,所以希望你會溫柔。Ant&Concordion:類路徑問題

試圖建立一個Ant任務自動運行我的Concordion驗收測試並生成彙總/概述/指數html頁面,列出哪些測試通過,失敗等

我使用Concordion Ant Task,但有一個問題我相信我的類路徑不正確。

封裝結構是鏡像測試/ java/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) 

回答

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測試。
  • <test> sub-entiity的name參數應該是要執行的類的名稱。我不認爲Overview是。
  • 不要停止JUnit測試失敗。一次測試可能失敗,但其他測試可能已成功。