TestNG之执行顺序
如果很有个测试方法,并且这几个方法又有先后顺序,那么如果让TestNG按照自己想要的方法执行呢
一、通过Dependencies
1.在测试类中添加Dependencies
@Test
public void test1() {
System.out.println("this is test1");
}
@Test(dependsOnMethods = { "test1" })
public void test2() {
System.out.println("this is test2");
}
@Test(dependsOnMethods = { "test2" })
public void test3() {
System.out.println("this is test3");
}
@Test(dependsOnMethods = { "test3" })
public void test4() {
System.out.println("this is test4");
}
@Test(dependsOnMethods = { "test4" })
public void test5() {
System.out.println("this is test5");
}
执行顺序,print:
this is test1
this is test2
this is test3
this is test4
this is test5
2.在xml文件中添加Dependencies,代码中无需再添加Dependencies
<test name="Test">
<classes>
<class name="test.testng.TestOrder"/>
<methods>
<dependencies>
<method name="test2" depends-on="test1"/>
<method name="test3" depends-on="test2"/>
<method name="test4" depends-on="test3"/>
<method name="test5" depends-on="test4"/>
<method name="test1" />
</dependencies>
</methods>
</classes>
</test>
执行顺序,打印结果:
this is test1
this is test2
this is test3
this is test4
this is test5
二、通过preserve-order="true"
在xml添加<suite name="Suite" preserve-order="true">,方法将按照XML中配置的先后顺序由上按下执行(代码无需额外控制)
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" preserve-order="true">
<test name="Test">
<classes>
<class name="test.testng.TestOrder"/>
<methods>
<include name="test2" />
<include name="test3" />
<include name="test1" />
</methods>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
执行顺序,打印结果:
this is test2
this is test3
this is test1
三、并发执行,Parallel
1、如果没有并发执行用例的需要,建议把Parallel=false,如果等于Parallel=true,则会并发执行用例,除非你设置了Dependencies,否则执行的顺序将不受控制
如:<suite name="Suite" parallel="true">
2、添加Parallel的时候也可以设置线程数,如:
<suite name="My suite" parallel="methods" thread-count="5">
<suite name="My suite" parallel="tests" thread-count="5">
<suite name="My suite" parallel="classes" thread-count="5">
<suite name="My suite" parallel="instances" thread-count="5">
官方的解释,有兴趣的可以自行翻译:
parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.
parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.
parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.
parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
Additionally, the attribute thread-count allows you to specify how many threads should be allocated for this execution.
TestNG之执行顺序的更多相关文章
- TestNG测试执行顺序
1.preserve-order属性,之前一直认为preserve-order属性是控制配置方法的执行顺序的,其实不是,preserve-order主要是控制test下节点classes执行顺序的 例 ...
- testNG设置测试的执行顺序
在java类中,设置Test的执行顺序可以使用priority,或者enabled等属性.但是在testng.xml中,需要设置它的 preserve-order="true" 另 ...
- TestNG学习-002-annotaton 注解概述及其执行顺序
此文主要讲述用 TestNG 基础的 annotation (注解)知识,及其执行的顺序,并通过一个 TestNG 简单的实例演示 annotation 的执行顺序. 希望能对初学 TestNG 测试 ...
- 使用TestNG框架测试用例执行顺序问题
既然是讨论执行顺序问题,那么用例肯定是批量执行的,批量执行的方法有mvn test.直接运行testng.xml文件,其中直接运行testng.xml文件的效果与pom文件中配置执行testng.xm ...
- 14、testng.xml 设置用例执行顺序
目录如下: TestGroup.java 代码如下: package com.testng.cn; import org.testng.annotations.*; import static org ...
- testng基础知识:注解的执行顺序
1. 单类,无继承父子关系 code: public class basicTest { @BeforeSuite(alwaysRun = true) public void beforeSuite_ ...
- JMeter学习-005-JMeter 主要组件概要介绍及执行顺序
本文将对 JMeter 主要组件(主要涉及 Threads(Users).Test Fragment.逻辑控制器.配置元件.定时器.前置处理器.Sampler.后置处理器.断言.监听器 十大组件)进行 ...
- TestNG-详解preserve-order的作用与测试case的执行顺序
在TestNG xml配置文件中,关于<test>的配置里面,有一个属性叫preserve-order,一开始以为这个属性可以用来控制测试case(那些被@Test注解标注的方法)的执行顺 ...
- python unittest控制用例的执行顺序
为什么要进行顺序控制呢?使用过testng的同学就知道,它相对于junit来说有更强大的功能,其中的一个功能就是依赖测试.什么是依赖测试呢?简单的说一下就是,A方法运行时,其中有个变量的取值是B方法的 ...
随机推荐
- struts2进阶篇(5)
一.OGNL简介 OGNL (Object-Graph Navigation Language)的缩写,简称对象图导航语言. OGNL表达式的特特点: >能够取对象的属性,也能调用对象的方法. ...
- Spring InitializingBean和init-method
原文转自:http://blog.csdn.net/shaozheng1006/article/details/6916940 InitializingBean Spirng的Initiali ...
- 初识Asp.net Identity
第一篇,多多指教啦! 之前做asp.net的网站只知道Asp.net的身份验证方式有:Windows验证和Forms验证.今天初步了解了下asp.net的Identity技术,顺带了解了它之前的Mem ...
- Js中的this指向问题
函数中的this指向和当前函数在哪定义的或者在哪执行的都没有任何的关系分析this指向的规律如下: [非严格模式]1.自执行函数中的this永远是window [案例1] var obj={ fn:( ...
- React对话框组件实现
当下前端届最火的技术之一莫过于React + Redux + webpack的技术结合.最近公司内部也正在转react,这周主要做了个React的modal组件,接下来谈下具体实现过程. 基本的HTM ...
- 初学Node(五)文件I/O
文件读写 Node的出现的一个亮点就是让JS也有了读写文件的能力,而且实现起来要比其他语言更简单,对文件的一些操作我们都可通过fs模块来完成.fs即fileSystem的缩写,fs模块可以完成对文件的 ...
- 维翔主机asp主机使用遇到的问题及解决方案总结
1.数据库配置 在这里,我们会发现,红色圈起来的部分"Webadmin"处点击之后会报错,这是因为,数据库管理工具没有进行域名解析,需要在域名购买商处添加一个域名解析,mssql, ...
- Ajax基本知识
1.创建xhr对象 var xmlhttp; if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari x ...
- .NET破解之google瓦片下载及拼接
由于最近一些其他事忙,加之电脑显卡坏了,所以,好长一段时间没有更新博客了,感觉对不注关注我的朋友.从本文开始,博客更新频率将会大大降低,但每周都会更新的. 在上帝之眼论坛看到了新出来了一个google ...
- Ettercap中间人攻击--介绍
前言 Ettercap有四种界面:Text,Curses,GTK2,Daemonize. -T 命令行界面,只显示字符.通常与配套的参数有-q(安静模式),加上该选项,则不会显示抓到的数据包 ...