gpt4 book ai didi

python - Robot Framework 中相互依赖测试的自动失败/不执行

转载 作者:行者123 更新时间:2023-11-28 19:43:21 26 4
gpt4 key购买 nike

我有大量的测试用例,其中几个测试用例是相互依赖的。是否有可能在执行稍后的测试用例时,您可以找出先前执行的测试用例的状态?在我的例子中,第 99 个测试用例取决于一些先前测试用例的状态,因此,如果第 24 个或第 38 个失败,我希望第 99 个测试用例根本不被执行,从而节省我很多时间。请尽可能用一些例子来解释。提前致谢!

最佳答案

Robot 具有很强的可扩展性,2.8.5 版中引入的一项功能可以轻松编写一个关键字,如果另一个测试失败,该关键字将失败。此功能是 library to act as a listener 的能力.有了这个,图书馆可以跟踪每个测试的通过/失败状态。有了这些知识,您就可以创建一个在其他测试失败时立即失败的关键字。

基本思想是,在每个测试完成时缓存通过/失败状态(通过特殊的 _end_test 方法)。然后,使用这个值来判断是否立即失败。

以下是如何使用此类关键字的示例:

*** 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"]

关于python - Robot Framework 中相互依赖测试的自动失败/不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25075706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com