RobotFramework中的执行顺序以及乱序执行策略

本文介绍了RobotFramework中如何实现测试用例的乱序执行,并详细解释了不同执行级别的随机化选项,包括测试用例级别、测试套件级别以及全部级别的乱序执行方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先我们先看看我们的测试执行顺序

Suite Setup   === 所有suite的初始化等工作,如果测试中含有不同的suite,每个suite可以不同的setup,setup不是必须的

Test case setup    == 每条测试用例前会运行该方法,确认所有测试用例的setup,当然单个测试用例,可以有自己的setup

Test case1 execution

Test case teardown   == 每条测试用例结束都运行这个函数,可以在这里做case的清理工作,比如退回到桌面,出错时截图等等

Test case setup

Test case2 .。。。 execution

Test case teardown

Suite Teardown == suite的清理工作

 

在上面我们看到所有的测试用例都是test1 test2 testN等顺序执行,当我们测试用例使用过程中,第一次或前几次能够发现问题,可是后来发现不了任何问题了,是不是我们的执行顺序固话导致呢?很有这种可能,根据以前的经验和教训来说,这种可能性很大,特别是项目的初始及中期。

所以亟待我们寻找一种乱序执行法,来满足测试用例乱序执行,发现应用之间相互影响带来的问题。

对于RobotFramework,我们使用如下方法来乱序执行:

3.4.7   Randomizing execution order

The test execution order can be randomized using option --randomize <what>[:<seed>], where <what> is one of the following:

tests

Test cases inside each test suite are executed in random order. 我们常用的是这个选项

suites

All test suites are executed in a random order, but test cases inside suites are run in the order they are defined.

all

Both test cases and test suites are executed in a random order.

none

Neither execution order of test nor suites is randomized. This value can be used to override the earlier value set with --randomize.

Starting from Robot Framework 2.8.5, it is possible to give a custom seed to initialize the random generator. This is useful if you want to re-run tests using the same order as earlier. The seed is given as part of the value for --randomize in format <what>:<seed> and it must be an integer. If no seed is given, it is generated randomly. The executed top level test suite automatically gets metadata named Randomized that tells both what was randomized and what seed was used.

Examples:

pybot --randomize tests my_test.txt
pybot --randomize all:12345 path/to/tests
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值