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方法的 ...
随机推荐
- windows下react-native环境搭建
首先不得不先吐槽一下自己,一个坑总是踩很多次,且乐此不疲. 咋办? 写博客记录记录呗. 零.记录的点 Java环境的下载与配置 Android环境的下载与配置 Node环境的下载与配置 创建第一个re ...
- oracle user account locked
1.Question describe when you use account scott/tiger connect to oracle, you will see "the user ...
- 转载Quandl R Package
Quandl R Package 通过Quandl API可以快速准确地获取宏观经济数据.(https://www.quandl.com/docs/api) 分享两个国外的优秀网站 R和Python在 ...
- JavaScript来实现打开链接页面(转载)
在页面中的链接除了常规的方式以外,如果使用javascript,还有很多种方式,下面是一些使用javascript,打开链接的几种方式: 1.使用window的open方法打开链接,这里可是在制定页面 ...
- Js中的this指向问题
函数中的this指向和当前函数在哪定义的或者在哪执行的都没有任何的关系分析this指向的规律如下: [非严格模式]1.自执行函数中的this永远是window [案例1] var obj={ fn:( ...
- android ImageSwitcher
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android=&q ...
- Python数据结构与算法--List和Dictionaries
Lists 当实现 list 的数据结构的时候Python 的设计者有很多的选择. 每一个选择都有可能影响着 list 操作执行的快慢. 当然他们也试图优化一些不常见的操作. 但是当权衡的时候,它们还 ...
- MyBatis入门(一)---基本使用
一.MyBatis简介 1.1.概述 MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. M ...
- 快速与MySQL交互,使用XMAPP打开MySQL数据库,并用shell进行与MySQL交互<Window 10>
1.如果想要通过XAMPP shell登录MySQL,还需要下载安装好XAMPP. 2.双击打开xampp-control.exe,会出现以下界面,点击开启Apache和MySQL,这样我们就开启服务 ...
- 使用 eclipse+egit 将项目提交至 github ,本地的git仓库:eclipse工作项目目录
新建github仓库 写一个github上仓库的名字,系统会自动检测重复性,无重复则可以提交 大于号代表有需要提交的东西 ...