TestNG之执行顺序

发表于:2016-1-04 12:01

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:乔叶叶    来源:51Testing软件测试网采编

分享:
  二、通过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.
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号