自动失败/不执行机器人框架中的相互依赖测试
-
26-12-2019 - |
题
如果说我是100个测试用例,以便在哪个测试案例中运行24,38和99是相互依存的。那么,虽然第99个测试案例正在执行,但是找出了先前执行的测试用例的状态(例如24或38测试用例)? 在我的情况下,第99次测试用例取决于第38次和第24个测试用例的状态,因此,如果24日或第38次失败,我希望第99个测试用例根本不会被执行,从而节省我很多时间。 请尽可能用一些例子解释。提前谢谢!
解决方案
一旦机器人开始运行,就无法跳过基于某些条件的测试。我认为这是机器人的弱点之一,但设计师真的不喜欢跳过测试的概念。此外,一个测试没有内置的方式取决于另一个测试。一个这个非常特征的功能请求被拒绝。
但是,机器人非常可扩展,并且在2.8.5版本中引入的功能使得如果另一个测试失败,则可以轻松地编写将失败的关键字。本功能是A 库充当侦听器。有了这个,库可以跟踪每个测试的通过/失败状态。通过该知识,如果某些其他测试失败,您可以创建一个关键字。基本思想是,将通过/失败状态缓存,因为每个测试完成(通过特殊的世代odicetagcode方法)。然后,使用此值来确定是否立即失败。
这是如何使用此类关键字的示例:
*** Settings ***
| Library | /path/to/DependencyLibrary.py
*** Test Cases ***
| Example of a failing test
| | fail | this test has failed
| Example of a dependent test
| | [Setup] | Require test case | Example of a failing test
| | log | hello, world
.
以下是库定义:
from robot.libraries.BuiltIn import BuiltIn
class DependencyLibrary(object):
ROBOT_LISTENER_API_VERSION = 2
ROBOT_LIBRARY_SCOPE = "GLOBAL"
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self
self.test_status = {}
def require_test_case(self, name):
key = name.lower()
if (key not in self.test_status):
BuiltIn().fail("required test case can't be found: '%s'" % name)
if (self.test_status[key] != "PASS"):
BuiltIn().fail("required test case failed: '%s'" % name)
return True
def _end_test(self, name, attrs):
self.test_status[name.lower()] = attrs["status"]
. 其他提示
要解决这个问题,我正在使用这样的东西:
Run Keyword if '${PREV TEST STATUS}'=='PASSED' myKeyword
.
所以也许这也可以为您使用。
不隶属于 StackOverflow