RobotFramework源码入口及测试

1、下载RobotFramework源码 https://github.com/robotframework/robotframework

2、入口文件为src/robot 目录下的run.py文件

3、打开run.py文件可看到:

if __name__ == '__main__':
    run_cli(sys.argv[1:])

4、跟踪到run_cli方法,代码如下。可以看到注释,根据注释中的例子我们来写一个测试用例:

def run_cli(arguments=None, exit=True):
    """Command line execution entry point for running tests.

    :param arguments: Command line options and arguments as a list of strings.
        Starting from RF 3.1, defaults to ``sys.argv[1:]`` if not given.
    :param exit: If ``True``, call ``sys.exit`` with the return code denoting
        execution status, otherwise just return the rc. New in RF 3.0.1.

    Entry point used when running tests from the command line, but can also
    be used by custom scripts that execute tests. Especially useful if the
    script itself needs to accept same arguments as accepted by Robot Framework,
    because the script can just pass them forward directly along with the
    possible default values it sets itself.

    Example::

        from robot import run_cli

        # Run tests and return the return code.
        rc = run_cli(['--name', 'Example', 'tests.robot'], exit=False)

        # Run tests and exit to the system automatically.
        run_cli(['--name', 'Example', 'tests.robot'])

    See also the :func:`run` function that allows setting options as keyword
    arguments like ``name="Example"`` and generally has a richer API for
    programmatic test execution.
    """
    if arguments is None:
        arguments = sys.argv[1:]
    return RobotFramework().execute_cli(arguments, exit=exit)

5、在utest包中新建一个测试用例:此处我命名为testcase.py.代码如下,其中D:\\RF\\TestProject\\TestSuit.txt为用例存储路径:

import unittest
from robot import run_cli


class TestCase(unittest.TestCase):

    def runTest(self):
        rc = run_cli(['--name', 'Example', 'D:\\RF\\TestProject\\TestSuit.txt'], exit=False)


if __name__ == "__main__":
    unittest.main()

6、TestSuit.txt内容如下:

*** Test Cases ***
Testcase
    Log    Hello

7、执行新建的testcase.py文件即可跟踪源码。

以上用例均通过测试。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值