(testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决
问题描述如下:
We use TestNG and Selenium WebDriver to test our web application.
Now our problem is that we often have several tests that need to run in a certain order, e.g.:
- login to application
- enter some data
- edit the data
- check that it's displayed correctly
Now obviously these tests need to run in that precise order.
At the same time, we have many other tests which are totally independent from the list of tests above.
So we'd like to be able to somehow put tests into "groups" (not necessarily groups in the TestNG sense), and then run them such that:
- tests inside one "group" always run together and in the same order
- but different test "groups" as a whole can run in any order
The second point is important, because we want to avoid dependencies between tests in different groups (so different test "groups" can be used and developed independently).
Is there a way to achieve this using TestNG?
Solutions we tried
- At first we just put tests that belong together into one class, and used
dependsOnMethodsto make them run in the right order. This used to work in TestNG V5, but in V6 TestNG will sometimes interleave tests from different classes (while respecting the ordering imposed bydependsOnMethods). There does not seem to be a way to tell TestNG "Always run tests from one class together". - We considered writing a method interceptor. However, this has the disadvantage that running tests from inside an IDE becomes more difficult (because directly invoking a test on a class would not use the interceptor). Also, tests using
dependsOnMethodscannot be ordered by the interceptor, so we'd have to stop using that. We'd probably have to create our own annotation to specify ordering, and we'd like to use standard TestNG features as far as possible. - The TestNG docs propose using
preserve-orderto order tests. That looks promising, but only works if you list every test method separately, which seems redundant and hard to maintain.
Is there a better way to achieve this?
I am also open for any other suggestions on how to handle tests that build on each other, without having to impose a total order on all tests.
PS
alanning's answer points out that we could simply keep all tests independent by doing the necessary setup inside each test. That is in principle a good idea (and some tests do this), however sometimes we need to test a complete workflow, with each step depending on all previous steps (as in my example). To do that with "independent" tests would mean running the same multi-step setup over and over, and that would make our already slow tests even slower. Instead of three tests doing:
- Test 1: login to application
- Test 2: enter some data
- Test 3: edit the data
we would get
- Test 1: login to application
- Test 2: login to application, enter some data
- Test 3: login to application, enter some data, edit the data etc.
In addition to needlessly increasing testing time, this also feels unnatural - it should be possible to model a workflow as a series of tests.
If there's no other way, this is probably how we'll do it, but we are looking for a better solution, without repeating the same setup calls.
he situation can easily be reproduced using the code snippet
below.
I'd be really glad if the ordering could natively be turned to "per class
atomicity"
------------ ClassA.java --------------
package test;
import org.testng.annotations.Test;
public class ClassA {
@Test
public void testA1()
{
System.out.println ("testA1");
}
@Test
public void testA2()
{
System.out.println ("testA2");
}
@Test(dependsOnMethods={"testA1","testA2"})
public void testA3()
{
System.out.println ("testA3");
}
}
------------ ClassB.java --------------
package test;
import org.testng.annotations.Test;
public class ClassB {
@Test
public void testB1()
{
System.out.println ("testB1");
}
@Test
public void testB2()
{
System.out.println ("testB2");
}
@Test
public void testB3()
{
System.out.println ("testB3");
}
}
------------ testng.xml --------------
<?xml version="1.0" encoding="UTF-8"?>
<suite name="TestSuite" parallel="none">
<test name="MyTest">
<classes>
<class name="test.ClassA"/>
<class name="test.ClassB"/>
</classes>
</test>
</suite>
------ Output -------
[TestNG] Running:
/usr/users/arno/local_home/workspace/playground/src/test/testng_dependsOnOrdering.xml
testA1
testA2
testB1
testB3
testB2
testA3
I have like 30 test-classes each with 4 or 5 tests and have
dependsOnMethod on them. testng.xml would be unmanagable if I have to
add <test> for each one of them.
目前来说的解决办法:
the test-runner _interleaves_ different tests from different classes!
Tests in the same <test> tag will always be run interleaved, if you want them separate, you should probably put them in different <test> tags...
不知道testng后续会不会优化,这个的确很annoying
(testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决的更多相关文章
- @DisallowConcurrentExecution 注解的作用 【定时器执行完当前任务才开启下一个线程的方式】
转: @DisallowConcurrentExecution 注解的作用 2018年10月12日 16:42:40 fly_captain 阅读数:4317 Quartz定时任务默认都是并发执行 ...
- 类似智能购票的demo--进入页面后默认焦点在第一个输入框,输入内容、回车、right时焦点自动跳到下一个,当跳到select时,下拉选项自动弹出,并且可以按上下键选择,选择完成后再跳到下一个。
要实现的效果:进入页面后默认焦点在第一个输入框,输入内容.回车.right时焦点自动跳到下一个,当跳到select时,下拉选项自动弹出,并且可以按上下键选择,选择完成后再跳到下一个. PS:自己模拟的 ...
- 打开FTP服务器上的文件夹时发生错误,请检查是否有权限访问该文件夹
打开FTP服务器上的文件夹时发生错误,请检查是否有权限访问 在win98,winme,win2000,win2003下都能正常上传文件夹,但在winxp+sp2下同样的文件夹就可能出现问题 1. 打开 ...
- Android 6.0及以上版本号的执行时权限介绍
执行时权限(Runtime Permission)是Android 6.0( 代号为 Marshmallow,API版本号为 23)及以上版本号新增的功能.相比于以往版本号,这是一个较大变化. 本文将 ...
- linux下service+命令和直接去执行命令的区别,怎么自己建立一个service启动
启动一些程序服务的时候,有时候直接去程序的bin目录下去执行命令,有时候利用service启动. 比如启动mysql服务时,大部分喜欢执行service mysqld start.当然也可以去mysq ...
- JAVA设计方法思考之如何实现一个方法执行完毕后自动执行下一个方法
今天编程时,突然想起来在一些异步操作或Android原生库的时候,需要我们实现一些方法, 这些方法只需要我们具体实现,然后他们会在适当的时候,自动被调用! 例如AsyncTask,执行玩doInBac ...
- 让程序跳转到绝对地址0x100000去执行
网上比较火的一个题,让程序跳转到绝对地址去执行 :可以的实现方式为: ( (void(*)())0x4110e6)(); (*(void(*)())0x4110e6)(); (*((void(*)() ...
- 理清PHP在Linxu下执行时的文件权限
首先推荐一个linux权限的视频:Linux权限管理之基本权限,讲的非常好,看完后就基本明白了. 一.文件权限及所属 1.文件有三种类型的权限,为了方便期间,可以用数字来代替,这样可以通过数字的加减, ...
- 编写Linux中sh文件执行时出现莫名字符的问题
今天在项目中需要编写一个sh,执行一些初始化操作,然后调取原来的执行文件,但是我在操作中主要到了首行需要加入#!/bin/sh 的表达式,但是在执行时总是报错,原因是每次执行,表达式后边都会添加一个莫 ...
随机推荐
- Virtualbox虚拟机相关
Virtualbox虚拟机相关 Virtualbox是我一直使用的虚拟机,由于需要一些测试环境等,会经常使用多个虚拟机.经常捣腾.之前有涉及到一些virtualbox方面的问题的处理,并没有记录下来, ...
- log4j动态日志级别调整
1. 针对root logger的设置 log4j.rootLogger=INFO, CONSOLELogger.getRootLogger().setLevel(org.apache.log4j.L ...
- 83. Spring Boot 1.4单元测试【从零开始学Spring Boot】
在[27. Spring Boot Junit单元测试]中讲过1.3版本的单元测试方式,这里说说1.4和1.3有什么区别之处? 在1.3中单元测试这样子的类似代码: //// SpringJUnit支 ...
- BZOJ 3240 [Noi2013]矩阵游戏 ——费马小定理 快速幂
发现是一个快速幂,然而过不去. 怎么办呢? 1.十进制快速幂,可以用来练习卡时. 2.费马小定理,如果需要乘方的地方,可以先%(p-1)再计算,其他地方需要%p,所以需要保存两个数. 然后就是分类讨论 ...
- weixin-api生成二维码
二维码长链接转成短链接(减少扫描时间和提高成功率) 微信返回正确的二维码的结果,参数有个url,即二维码图片解析后的地址,也可以根据此URL生成需要的二维码图片,而不需要通过ticket去换取图片了 ...
- 【译】NCCloud: Applying Network Coding for the Storage Repair in a Cloud-of-Clouds
NCCloud:多云存储设备下存储修复的网络编码 Yuchong Hu, Henry C. H. Chen, Patrick P. C. Lee, Yang Tang 摘要:近年来的研究提出通过条带 ...
- NOIP[2015] 运输计划(codevs 4632)
题目描述 Description 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航道建立在两个星球之间,这 n−1 条航道连通了 L 国的所有星球.小 P ...
- 家用电脑架服务器提供web
要搞一个可以对外的web服务,需要服务器,域名.这些都需要money,但有时,我们只是想自己可以在外面访问,或是提供给朋友看自己的网站有多牛.这时使用家用电脑配置一个可以提供web的服务器,就显得很必 ...
- 矩阵乘法 BZOJ 2738
矩阵乘法 [问题描述] 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. [输入格式] 第一行两个数N,Q,表示矩阵大小和询问组数:接下来N行N列一共N*N个数,表示这个矩阵: ...
- Perl语言入门--4--函数
1.chop函数:删除标量变量或数组中每个字符的最后一个字 举个栗子: #!/usr/bin/perl $v = 'Flowers'; $r = chop($v); print "$v (w ...