变量测试的经过时间和结果 [英] Elapsed time and result of a test in variables

查看:41
本文介绍了变量测试的经过时间和结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在变量中确定经过的时间和当前测试的结果?

Is it possible to determine the elapsed time and the result of the current test in a variable?

我想要一些测试来记录他们在外部系统中的结果,所以最好在 [拆解] 中我想知道:

I'd like some tests to log their results external systems, and so ideally in [Teardown] I'd like to know:

  • 当前测试的经过时间
  • 测试结果

这可能吗?

推荐答案

在每个关键字、测试和套件的执行结束时,侦听器接口提供了一个以毫秒为单位的经过时间.请参阅用户中标题为 使用侦听器的部分指导.

The listener interface provides an elapsed time in milliseconds, at the end of execution of each keyword, test, and suite. See the section titled Taking listeners into use in the user guide.

从机器人框架 2.8.5 开始,您可以在库中实现侦听器,这意味着您可以将此功能构建到测试套件中,而不是依赖于命令行选项来设置侦听器.请参阅用户中标题为作为侦听器的测试库的部分指导.

Starting with robot framework 2.8.5 you can implement listeners in a library, meaning you can build this functionality into a test suite, rather than depending on command line options to set up the listener. See the section titled Test libraries as listeners in the user guide.

以下示例展示了如何实现侦听器接口.该库会打印名称、状态和经过的时间,但您也可以轻松调用 Web 服务、将数据插入数据库或将数据写入文件.

The following example shows how you might implement the listener interface. The library prints the name, status and elapsed time, but you could just as easily call a web service, insert the data into a database, or write the data to a file.

class ReporterLibrary(object):
    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
    ROBOT_LISTENER_API_VERSION = 2

    def __init__(self):
        self.ROBOT_LIBRARY_LISTENER = self

    def _end_test(self, name, attrs):
        print "%s => status: %s, elapsed time: %s ms" % (name, attrs['status'], attrs['elapsedtime'])

示例.robot

*** Settings ***
| Library | ReporterLibrary.py

*** Test Cases ***
| Example of a passing test
| | sleep | 200 milliseconds
| | Pass execution | test passed

| Example of a failing test
| | sleep | 500 milliseconds
| | Fail | test failed

这篇关于变量测试的经过时间和结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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