[setup]
[teardown]
1. Use case level:
(1) Setup and teardown are only valid for the current use case
(2) Setup and teardown can be used separately, and it is not mandatory to appear in pairs
Code example:
*** Test Cases ***
# 用例级别的setup与teardown,只对当前用例有效
# setup和teardown可以单独使用,不强制要求成对出现
case1
[Setup] log to console 执行用例初始化操作
[Teardown] log to console 执行用例清除操作
log to console 执行测试用例
case2
[Setup] log to console 执行用例初始化操作2
[Teardown] log to console 执行用例清除操作2
log to console 执行测试用例2
operation result:
2. Test suite level
(1) Write in the Settings table of the test suite file
(2) Two types
- Suite setup/teardown: Enter and exit this suite, before and after the execution of the use case, perform initialization and removal only once, respectively
*** Settings ***
# 套件级别:
Suite Setup log to console ------套件级别:初始化-------
Suite Teardown log to console ------套件级别:清除-------
*** Test Cases ***
# 用例级别的setup与teardown,只对当前用例有效
# setup和teardown可以单独使用,不强制要求成对出现
case1
log to console 执行测试用例1
case2
log to console 执行测试用例2
operation result:
- Test setup/teardown: If the use case in the suite does not have a setup/teardown, it will be executed (for each use case)
*** Settings ***
# 套件级别:
Suite Setup log to console ------套件级别:初始化-------
Suite Teardown log to console ------套件级别:清除-------
Test Setup log to console -------套件级别:默认初始化,如果用例自带初始化,则不执行-------
Test Teardown log to console -------套件级别:默认清除,如果用例自带初始化,则不执行-------
*** Test Cases ***
# 用例级别的setup与teardown,只对当前用例有效
# setup和teardown可以单独使用,不强制要求成对出现
case1
log to console 执行测试用例1
[Setup] log to console ------用例1:初始化操作--------
case2
log to console 执行测试用例2
operation result:
3. Directory level
(1) In the directory, create a new file __init__.robot, write suite-level initialization and cleanup operations in it
(2) Will execute it again: Suite Setup/teardown, and then Test Setup/teardown in the use case follows the principle of proximity
operation result:
(3) If you only want to execute a certain package under the directory, but also want to use directory-level initialization and removal, you can specify it on the command line with the -s parameter
Such as: robot -s package name directory name