@Test
 
testNG1.java:
import org.testng.annotations.Test;

public class testNG1 {
@Test
public void testNg() {
System.out.println("this is testNG1");
}
}
testNG2.java:
import org.testng.annotations.Test;

public class testNG2 {
@Test
public void testNg() {
System.out.println("this is testNG2");
}
}
 
testNG3.java:
import org.testng.annotations.Test;

public class testNG3 {
@Test
public void testNg() {
System.out.println("this is testNG3");
}
}
 
testng.xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Regression1" >
<classes>
<class name="testNG2" />
<class name="testNG1" />
<class name="testNG3" />
</classes>
</test>
</suite>
运行testng.xml,执行结果:
this is testNG1
this is testNG2
this is testNG3
 
 
preserve-order="true"
 
默认testng.xml是按字典的顺序执行,如果想要按照xml中class的顺序执行,可以在test节点加上preserve-order="true",修改testng.xml如下:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Regression1" preserve-order="true" >
<classes>
<class name="testNG2" />
<class name="testNG1" />
<class name="testNG3" />
</classes>
</test>
</suite>
再次运行testng.xml,执行结果:
this is testNG2
this is testNG1
this is testNG3
 
 
preserve-order="true"属性同样适用于class中的方法
 
testNG4.java
import org.testng.annotations.Test;

public class testNG4 {
@Test
public void testNgMethond1() {
System.out.println("this is testNgMethond1");
} @Test
public void testNgMethond2() {
System.out.println("this is testNgMethond2");
} @Test
public void testNgMethond3() {
System.out.println("this is testNgMethond3");
}
}

testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Regression1">
<classes>
<class name="testNG4" />
<methods>
<include name="testNgMethond3"></include>
<include name="testNgMethond2"></include>
<include name="testNgMethond1"></include>
</methods>
</classes>
</test>
</suite>
运行testng.xml,执行结果:
this is testNgMethond1
this is testNgMethond2
this is testNgMethond3
 
如果想要按照xml中方法的顺序执行,同样在test节点加上preserve-order="true",修改testng.xml如下:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Regression1" preserve-order="true">
<classes>
<class name="testNG4" />
<methods>
<include name="testNgMethond3"></include>
<include name="testNgMethond2"></include>
<include name="testNgMethond1"></include>
</methods>
</classes>
</test>
</suite>

再次运行testng.xml,执行结果:

this is testNgMethond3
this is testNgMethond2
this is testNgMethond1
总之,如果希望xml中的class或者method按照顺序执行的话,就在test节点加上preserve-order="true"

testNG之顺序执行的更多相关文章

  1. testng.xml顺序执行多个case配置

    testng.xml顺序执行多个case配置 项目结构如图:

  2. 使用TestNG框架测试用例执行顺序问题

    既然是讨论执行顺序问题,那么用例肯定是批量执行的,批量执行的方法有mvn test.直接运行testng.xml文件,其中直接运行testng.xml文件的效果与pom文件中配置执行testng.xm ...

  3. testng xml中按顺序执行java类

    如红字部份,将安顺序执行4个类 <?xml version="1.0" encoding="UTF-8"?><suite name=" ...

  4. js的并行加载以及顺序执行

    重新温习了下这段内容,发现各个浏览器的兼容性真的是搞大了头,处理起来很是麻烦. 现在现总结下并行加载多个js的方法: 1,对于动态createElement('script')的方式,对所有浏览器都是 ...

  5. 【原创】cs+html+js+css模式(七): 顺序执行与并发执行问题,IIS7及其以上版本的抛错问题解决

          在进行开发的过程中,针对于这种模式,我们继承的IRequiresSessionState,这种对于我们的同一个IIS的执行中是顺序执行即一个ajax请求处理完成后,才能执行下一个ajax, ...

  6. js的并行加载与顺序执行

    javaScript文件(下面简称脚本文件)需要被HTML文件引用才能在浏览器中运行.在HTML文件中可以通过不同的方式来引用脚本文件,我们需要关注的是,这些方式的具体实现和这些方式可能会带来的性能问 ...

  7. gulp顺序执行任务

    gulp的任务的执行是异步的. 所以,当我写完一系列的任务,准备一股脑地执行. # gulp.task('prod', ['clean', 'compass', 'image', 'style', ' ...

  8. 顺序执行到来的消息 actor

    在某项目里,有个 actor 需要做一些持久化的操作,这些操作耗时比较久,理应使用异步的代码来写,但是需求又强调每次只能做一个持久化操作,后来的请求应该等待.一个显然的做法是阻塞式的写,这样就能比较简 ...

  9. 多命令顺序执行、管道符 ; && || |

    多命令顺序执行:

随机推荐

  1. UiAutomator、UiAutomator2、Bootstrap的关系

    很多同学经过一段时间的学习之后都明白了Appium的基本原理,但是越学习到后面发现出现的很多陌生名词无法弄清楚其具体作用,今天这篇文章的目的就是为了让大家来弄懂三个高频名词:UiAutomator.U ...

  2. Linux配置postfix

    启动报错:主机名不能以数字开头,否则报错

  3. 创建Spring Boot 工程

    先在eclipse中安装spring -tool -suite插件,然后根据以下步骤可以创建   1.新建Spring Starter Project 2.Packaging 选择 jar 3.勾选W ...

  4. LocalActivityManager如何在一个Activity的一部分中显示其他Activity

    首先要使用该方法,页面必须继承ActivityGroup. 总的来说,实现"如何在一个Activity的一部分中显示其他Activity"除了LocalActivityManage ...

  5. 前端每日实战:36# 视频演示如何利用 CSS 动画原理,在页面上表现日蚀现象

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/OELvrK 可交互视频教程 此视频 ...

  6. python中将12345转换为'12345',不要使用str

    a = 12345 #创建一个空字符串 ret = "" #whlie循环,条件为当a为true时,即a不是 0的时候 while a : #定义一个变量,对a求余 last = ...

  7. 2018-2019-2 20175203 实验四《Android 开发基础》

    20175203 2018-2019 实验四<Android 开发基础> 实验要求 参考Android开发简易教程 完成云班课中的检查点,也可以先完成实验报告,直接提交.注意不能只有截图, ...

  8. Scribd每月共有超过两亿个访客、累积数亿篇以上的文件档案,Alexa全球排名200以内

    目前已登上世界300大网站,每月共有超过两亿个访客.累积数亿篇以上的文件档案.透过Flash介面的阅读器-iPaper,使用者可以在网站内浏览各种文件,由于该网站是一个文件分享平台,所有的文件都是由使 ...

  9. 信息安全-OAuth2.0:NuGetFromMicrosoft

    ylbtech-信息安全-OAuth2.0:NuGetFromMicrosoft 1.返回顶部 1. https://login.microsoftonline.com/common/oauth2/v ...

  10. javascript标签放置位置

    首先:放置位置哪里都能放 但是js代码很有可能不起作用:例如:往id为span的标签中定时插入数字 var time=document.getElementById("span") ...