@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. Linux 多个cpp文件的编译(Makefile)

    打包so文件: CC = g++ CFLAGS=-Wall -O2 -fPIC TARGET = libbg.so SRCS := $(wildcard *.cpp) OBJS := $(patsub ...

  2. 七、单例设计模式共享数据分析、解决、call_once

    一.设计模式大概谈 代码的一些写法,与常规的写法不太一样,程序灵活,维护起来很方便,但是别人接管.阅读代码很痛苦. 用设计模式理念写出来的代码很晦涩.<< head first>&g ...

  3. flutter网格布局之GridView组件

    前面总结了使用ListView来实现列表,但是,有的时候,数据量很大,需要使用矩阵方式排列才能更清晰的展示数据,在flutter中,可以使用网格列表组件GridView来实现这个布局. GridVie ...

  4. flutter中的列表组件

    列表布局是我们项目开发中最常用的一种布局方式.Flutter 中我们可以通过 ListView 来定义列表项,支持垂直和水平方向展示.通过一个属性就可以控制列表的显示方向.列表有以下分类:  垂直列表 ...

  5. UOJ 418 【集训队作业2018】三角形——思路+线段树合并

    题目:http://uoj.ac/problem/418 看了题解才会…… 很好的想法是把整个过程看成若干 “取一点 i ,值+=w[ i ],值-=\(\sum w[j]\)”(其中 j 是 i 的 ...

  6. POJ3233]Matrix Power Series && [HDU1588]Gauss Fibonacci

    题目:Matrix Power Series 传送门:http://poj.org/problem?id=3233 分析: 方法一:引用Matrix67大佬的矩阵十题:这道题两次二分,相当经典.首先我 ...

  7. 20175126《Java程序设计》第十周学习总结

    # 20175126 2016-2017-2 <Java程序设计>第十周学习总结 ## 教材学习内容总结 - 本周学习方式主要为手动敲代码并理解内容学习. -本周学习十二章,主要内容如下: ...

  8. vs 2019 create new project 创建新项目

    下面的place solution and project in the same directory 不需要勾选

  9. 专家揭秘:STM32启动过程全解

    电子发烧友网核心提示:本文主要阐述了STM32启动过程全面解析,包括启动过程的介绍.启动代码的陈列以及深入解析. 相对于ARM上一代的主流ARM7/ARM9内核架构,新一代Cortex内核架构的启动方 ...

  10. Java8新特性-日期相关类操作

    JDK8以前使用SImpleDateFormate类格式化日期,因为在SImple DateFormate中存在Calendar实例引用,而在caleander中得establish中存在clear( ...