2011-11-21 56 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

相关问题