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文件即可跟踪源码。

以上用例均通过测试。

你可能感兴趣的:(Robot,Freamwork)