我得到了下面的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>
为什么是顺序错了吗?
我很感激帮助。
由于在文档读取/转换为对象 – kostja
时文档中XML节点的排序不会被强制,TestNG文档指出:“默认情况下,TestNG将运行您的测试按照它们在XML文件中的顺序排列如果您希望此文件中列出的类和方法以不可预测的顺序运行,请将preserve-order属性设置为false“如何获得此行为? – Tarken
然后请忽略我无关的评论:) – kostja