Skip to main content
 首页 » 编程设计

python之模板化机器人测试用例并不总是运行 Setup 和 Teardown 关键字

2024年11月01日8lori

我希望 Test Setup 和 Test Teardown 关键字在每次执行模板测试时运行,但事实似乎并非如此。这是我的测试套件的简化版本,它演示了我在说什么。我像 pybot template-problem.txt 一样运行它。请注意,生成的日志文件显示我的 Test Case Setup 和 Test Case Teardown 关键字分别只运行了一次。

*** Settings *** 
Test Setup        Test Case Setup 
Test Teardown     Test Case Teardown 
 
*** Test Cases *** 
Look for All Possible Outputs from the System Under Test 
    [Template]    Look for Specific Output 
    A 
    B 
    C 
    D 
    E 
    F 
    G 
    H 
    I 
    J 
    K 
    L 
    M 
    N 
    O 
    P 
    Q 
    R 
    S 
    T 
    U 
    V 
    W 
    X 
    Y 
    Z 
 
*** Keywords *** 
Test Case Setup 
    Comment    Setting up before the test case runs 
 
Test Case Teardown 
    Comment    Cleaning up after the test case finishes 
 
Look For Specific Output 
    [Arguments]    ${output} 
    Comment    Pretending to look for a specific output... 
    Log    ${output} 

请您参考如下方法:

来自Robot Framework documentation on test templates :

Whereas the body of the normal test case is constructed from keywords and their possible arguments, test cases with template define only the arguments for the template keyword.

因此,使用模板只是将您的测试用例转换为:

Look for All Possible Outputs from the System Under Test 
    Look for Specific Output    A 
    Look for Specific Output    B 
    Look for Specific Output    C 
    ... 

即它仍然只是一个测试用例,用不同的参数连续多次调用相同的关键字。