@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. 【优化】Mysql字段尽可能用NOT NULL

    下面咱们要聊的是 MySQL 里的 null,在大量的 MySQL 优化文章和书籍里都提到了字段尽可能用NOT NULL,而不是NULL,除非特殊情况.但却都只给结论不说明原因,犹如鸡汤不给勺子一样, ...

  2. 重写NSString的setter方法

    - (void)setName:(NSString *)name { _name = [name copy]; } 就可以了 不需要写成: 第一种: (void)setName:(NSString * ...

  3. Java Web学习总结(3)Servlet(二)

    一,Servlet访问URL映射配置 由于客户端是通过URL地址访问web服务器中的资源,所以Servlet程序若想被外界访问,必须把servlet程序映射到一个URL地址上,这个工作在web.xml ...

  4. PHP远程DoS漏洞深入分析及防护方案

    PHP远程DoS漏洞 4月3日,有人在PHP官网提交PHP 远程DoS漏洞(PHP Multipart/form-data remote dos Vulnerability),代号69364.由于该漏 ...

  5. python练习题之随机生成验证码

    #引用random模块下的randint项目#定义验证码函数.定义一个空字符串变量,分三种情况,随机产生的大写字母,随机产生的小写字母,随机产生的数字.然后#每一次执行哪一种情况,条件也是随机的,就是 ...

  6. php与js互相调用

    php中调用js <?php echo '<script>var yearid=$("#yearId").val()</script>'; echo ...

  7. Php邮件发送源码

    好久冒写点东西了.....最近生活压抑的很....为生活而劳累,整理下邮件发送的实例了,网上也有很多,我这个也是提取整理好的,测试Ok,首页邮件类smtp_email_class.php如下:< ...

  8. shell zip和unzip压缩和解压,压缩效率

    1.把/home目录下面的mydata目录压缩为mydata.zip zip -r mydata.zip mydata #压缩mydata目录zip -r mydata.zip ./*txt #压缩当 ...

  9. Cocos2d-x之定时器

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 每一个游戏程序都有一个循环在不断运行,它是由导演对象来管理与维护.如果需要场景中的精灵运动起来,可以在游戏循环中使用定时器对精灵等对象进行 ...

  10. Windows盘符切换,Dos命令

    >>.常用Dos命令 dir 列文件名 deltree 删除目录树 cls 清屏 cd 改变当前目录 copy 拷贝文件 diskcopy 复制磁盘 del 删除文件 format 格式化 ...