@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. 安装windows10和fedora23双系统的一些注意事项

    在安装双系统windows10和fedora的过程中遇到了很多的问题,博主也是在慢慢的摸索中最后莫名其妙的成功的安装双系统. 当然,幸亏博主机智的记住了中间的一些细节,所以大致上的有一些注意事项希望能 ...

  2. Python基础教程(018)--官方解释器交互运行

    前言: 在交互式运行Python程序 内容 在Python的shell中直接输入Python的代码,可以立即执行结果 交互式运行Python的优缺点 1,缺点--代码不能保存 2,不适合运行太大的程序 ...

  3. LOJ 3124 「CTS2019 | CTSC2019」氪金手游——概率+树形DP

    题目:https://loj.ac/problem/3124 看了题解:https://www.cnblogs.com/Itst/p/10883880.html 先考虑外向树. 考虑分母是 \( \s ...

  4. YII 1.0 常用CURD写法

    <?php //yii1.0 curd简单写法 //查询 Yii::app()->db->createCommand($sql)->queryAll();//查询所有行数据 ​ ...

  5. composer 国内加速,修改镜像源

    为什么慢 由于默认情况下执行 composer 各种命令是去国外的 composer 官方镜像源获取需要安装的具体软件信息,所以在不使用代理.不翻墙的情况下,从国内访问国外服务器的速度相对比较慢 如何 ...

  6. 通过注册表修改IE的Internet选项

    Internet Explorer 安全区域设置存储在以下注册表子项下面: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\I ...

  7. ajax请求controller出现中文乱码

    ajax请求controller出现中文乱码 解决方法:在 @RequestMapping 中加上  produces = {"application/json;charset=UTF-8& ...

  8. Maven 上传文件 Error creating bean with name 'multipartResolver':

    <!--配置MultipartResolver 处理文件上传--><bean id="multipartResolver" class="org.spr ...

  9. spring boot 尚桂谷学习笔记10 数据访问02 mybatis

    数据访问 mybatis 创建一个 springboot 工程,模块选择 sql 中 mysql(数据驱动), jdbc(自动配置数据源), mybatis Web模块中选择 web pom 引入: ...

  10. Python字符串前缀

    1,r/R表示raw string(原始字符串) #!/usr/bin/python str1 = 'hello \n world' str2 = r'hello \n world' print(st ...