2011-11-21 57 views
0

我得到了下面的testng.xml和build.xml文件:爲什麼Ant以錯誤的順序在testng.xml中運行testclasses?

<suite name="My test suite" preserve-order="true"> 
<parameter name="a" value="abcd"/> 
<parameter name="b" value="efgh"/> 

<test name="testing"> 
<classes> 
    <class name="test.First"/> 
    <class name="test.Second"> 
    <methods> 
     <exclude name="method1"/> 
    </methods> 
    </class> 
    <class name="test.Third"/> 
    <class name="test.Forth"> 
     <methods> 
      <exclude name="method3"/> 
     </methods> 
    </class> 
    <class name="test.Fifth"/> 
    <class name="test.Sixth"/> 
</classes> 

如果我執行我的IDE內的testng.xml的類被稱爲依次是:第一,第二,... ,第六個 但是,如果我用ANT運行下面的build.xml,這些類會按照如下錯誤順序調用:第六,第四,第五,第二,第三,第一。訂單更改。我認爲用TestNG這不應該發生?

的build.xml:

<project basedir="." default="build" name="Dummy"> 
<property environment="env"/> 
<property name="ECLIPSE_HOME" value="MyEclipse"/> 
<property name="debuglevel" value="source,lines,vars"/> 
<property name="target" value="1.6"/> 
<property name="source" value="1.6"/> 
<path id="classpath"> 
    <pathelement location="bin"/> 
    <pathelement location="../selenium-server-standalone-2.10.0.jar"/> 
    <pathelement location="testng.jar"/> 
</path> 
<target name="init"> 
    <mkdir dir="bin"/> 
    <copy includeemptydirs="false" todir="bin"> 
     <fileset dir="src"> 
      <exclude name="**/*.launch"/> 
      <exclude name="**/*.java"/> 
     </fileset> 
    </copy> 
</target> 
<target name="clean"> 
    <delete dir="bin"/> 
</target> 
<target depends="clean" name="cleanall"/> 
<target depends="init" name="build"> 
    <echo message="${ant.project.name}: ${ant.file}"/> 
    <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}" encoding="iso-8859-1"> 
     <src path="src"/> 
     <classpath refid="classpath"/> 
    </javac> 
</target> 
<taskdef name="testng" 
     classname="org.testng.TestNGAntTask" 
     classpathref="classpath"/> 
<target name="test" depends="build"> 
    <echo message="running tests"/> 
    <testng classpathref="classpath" outputdir="testng_output"> 
     <xmlfileset dir="bin" includes="testng.xml"/> 
    </testng> 
</target> 

爲什麼是順序錯了嗎?

我很感激幫助。

+0

由於在文檔讀取/轉換爲對象 – kostja

+0

時文檔中XML節點的排序不會被強制,TestNG文檔指出:「默認情況下,TestNG將運行您的測試按照它們在XML文件中的順序排列如果您希望此文件中列出的類和方法以不可預測的順序運行,請將preserve-order屬性設置爲false「如何獲得此行爲? – Tarken

+0

然後請忽略我無關的評論:) – kostja

回答

2

嗨,也許你正在使用兩個不同版本的testng,一個是由Eclipse插件包含的,另一個在你的類路徑中。關於preserve-order屬性有一個bug(http://code.google.com/p/testng/source/detail?r=966),可能是你的類路徑中存在bug的版本。嘗試更新由build.xml腳本引用的testng版本

+0

我會看看那個。 TestNG的Eclipse插件是6.3版本(我認爲是最新版本) – Tarken

+0

我只有插件的testng.jar和eclipse-testng.jar。在這兩者之間切換並不會改變行爲: -/ – Tarken

+0

我試着刪除並且ant仍然執行測試O_o我怎樣才能找出它使用的是哪個jar?我的班級路徑中沒有那個jar。 – Tarken

相關問題