自动失败/在机器人框架相互依存测试不执行 [英] Automatic failing/non-execution of interdependent tests in Robot Framework

查看:132
本文介绍了自动失败/在机器人框架相互依存测试不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果说我有一个100的测试用例来在测试情况下,没有24,38和99是相互依存的运行。那么有没有可能,虽然是越来越执行第99次测试情况下,你发现pviously执行测试用例$ P $的状态(比如24日或38测试用例)?
在我的情况下,第99测试用例依赖于第38的状态,24日测试案例,因此,如果设置了第24或第38个失败,我想第99测试用例完全不被执行,从而节省了我很多时间。
请,一些示例如果可能的解释。在此先感谢!

If say I've a 100 test cases to run in which test case no 24, 38 and 99 are interdependent. Then is it possible that while the 99th test case is getting executed you find out the status of a previously executed test case (say the 24th or 38th test case)? In my case, the 99th test case depends on the status of the 38th and the 24th test case and thus, if either the 24th or the 38th fails I would like the 99th test case NOT to get executed at all and thus save me a lot of time. Kindly, explain with some example if possible. Thanks in advance!

推荐答案

一旦机器人开始运行,有没有办法跳过基于某些条件的考验。我认为这是机器人的弱点之一,但设计师真的好像不喜欢跳过测试的概念。此外,还有一个测试依赖于另外一个没有内置的方式。对于这个非常功能的一个功能请求被拒绝

Once robot starts running, there's no way to skip a test based on some condition. I think this is one of the weaknesses of robot, but the designers really don't seem to like the notion of skipped tests. Also, there's no built-in way for one test to depend on another. A feature request for this very feature was declined.

不过,机器人是非常可扩展的,并且是在2.8.5版本引入的功能可以很容易地编写会失败关键字如果其他测试有failed.This的功能就是为的库充当听众。与此,图书馆可以保持合格的轨道/失败每个测试的状态。有了这些知识,你可以,如果其他一些测试失败创建立即失败关键字。

However, robot is very extensible, and a feature that was introduced in version 2.8.5 makes it easy to write a keyword that will fail if another test has failed.This feature is the ability for a library to act as a listener. With this, a library can keep track of the pass/fail status of each test. With that knowledge, you can create a keyword that fails immediately if some other test fails.

其基本思想是,缓存通过/失败状态,因为每个测试完成(通过特殊的 _end_test 方法)。然后,使用该值来确定是否立即或不会失败。

The basic idea is, cache the pass/fail status as each test finishes (via the special _end_test method). Then, use this value to determine whether to fail immediately or not.

下面是一个如何使用这些关键字的例子:

Here's an example of how to use such a keyword:

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

这篇关于自动失败/在机器人框架相互依存测试不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆