Java 为什么Ant以错误的顺序运行testng.xml中定义的TestClass?
我得到了以下testng.xml和build.xml:Java 为什么Ant以错误的顺序运行testng.xml中定义的TestClass?,java,ant,testng,Java,Ant,Testng,我得到了以下testng.xml和build.xml: <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"/>
<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>
<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>
如果我在IDE中执行testng.xml,则类的调用顺序为:第一、第二、…、第六
但是,如果我使用ANT运行下面的build.xml,则类的调用顺序是错误的:第六、第四、第五、第二、第三、第一。顺序改变了。我认为TestNG不应该发生这种情况
build.xml:
<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>
<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>
为什么订单错了
非常感谢您的帮助。您好,也许您正在使用两个不同版本的testng,一个包含在Eclipse插件中,另一个包含在您的类路径中。有一只虫子(http://code.google.com/p/testng/source/detail?r=966)在preserveorder属性上,您的类路径中可能有错误的版本。尝试升级build.xml脚本引用的testng版本,因为在将文档读取/转换为对象时,不会强制对文档中的xml节点进行排序testng文档声明:“默认情况下,TestNG将按照在XML文件中找到的顺序运行测试。如果您希望此文件中列出的类和方法以不可预测的顺序运行,请将preserve order属性设置为false“我如何获得此行为?请忽略我的无关注释:)我将查看一下。我的TestNG Eclipse插件是版本6.3(我认为是最新的)我只有插件中的testng.jar和eclipse-testng.jar。在这两者之间切换不会改变行为:-/我尝试删除了,ant仍然执行测试。我如何才能找出它使用的是哪个jar?我的类路径中没有这个jar。我试图重现您的问题,如果我从b中删除了testng.jar声明build.xml我甚至无法运行taks,因为找不到Taskdef TestNGAntTask。在我的类路径上有testng-6.3.jar,即使我运行build.xml,testng.xml的执行顺序也是正确的。您的类路径中必须有testng,请尝试查看项目属性。我从Eclipse Ant视图selenium服务器ja运行build.xml任务r包含与当前版本不相同的testng包我如何从testng.jar中排除那些实际使用当前版本的包?