声明robot框架测试之间的依赖关系
robotframework-dependencylibrar的Python项目详细描述
声明测试之间的依赖关系。使测试自动基于失败 其他测试用例或测试套件的结果。
尽管我强烈建议人们编写测试时要独立, 有时,测试之间的依赖关系是最简单和最容易的模型 实现,如果一个或多个以前的测试失败 没有得到预期效果的病例是有益的。
版本控制
这个库的版本号跟在SemVer 2.0.0 specification后面。
安装
pip install robotframework-dependencylibrary
用法
首先,在测试中包含库:
*** Settings ***LibraryDependencyLibrary
假设您有一个通过和不通过的测试:
*** Test cases ***Passing TestNo operationFailing TestFailThis test is intentionally hardcoded to fail
取决于通过测试的基本测试如下:
*** Test cases ***This Test Depends on "Passing Test" PassingDepends on testPassing TestLogThe rest of the keywords in this test will run as normal.
当然,您可以依靠测试失败来代替:
*** Test cases ***This Test Depends on "Failing Test" FailingDepends on test failureFailing TestLogThe rest of the keywords in this test will run as normal.
您还可以取决于测试套件的状态:
*** Test cases ***This Test Depends on an Entire Test Suite PassingDepends on suiteMy Test Suite NameLogThe rest of the keywords in this test will run as normal.
故障
因为Depends on ...关键字在依赖项不存在时失败 met,它支持您期望从robot框架获得的所有常规逻辑:
当Depends on ...关键字按预期失败时,测试用例会自动中止并失败,除非您捕获状态和 使用Run keyword and expect error之类的错误消息。
错误消息
错误信息被记录在案(并被视为 接口,因此您可以依赖semver语义:主要版本 如果错误消息的逻辑发生更改,则编号将被取消:
如果测试未通过,则会出现一个有用的错误:
*** Test cases ***This Test Depends on "Failing Test" PassingDepends on testFailing TestLogThe rest of the keywords (including this log) will NOT run!
错误信息为:
Dependency not met: test case 'Failing Test' state is 'FAIL', wanted 'PASS'
与期望通过测试失败相同:
*** Test cases ***This Test Depends on "Passing Test" FailingDepends on test failurePassing TestLogThe rest of the keywords (including this log) will NOT run!
错误信息为:
Dependency not met: test case 'Passing Test' state is 'PASS', wanted 'FAIL'
如果你输入了一个测试,或者试着依赖于之前测试的状态 它已运行,例如:
*** Test cases ***Depends on Non-Existant Test CaseDepends on testMisnamed Test
错误信息为:
Dependency not met: test case 'Misnamed Test' not found, wanted 'PASS'
如果你不小心让一个测试依赖于它自己,它会给出一个类似的 更准确地标识错误的错误消息:
*** Test cases ***Depends on selfDepends on testDepends on self
错误信息为:
Dependency not met: test case 'Depends on self' mid-execution, wanted 'PASS'
所有测试套件错误消息都是相同的,除了它们使用 用“测试套件”代替“测试用例”。
注意
如果需要以编程方式分析错误消息,请保留 请注意,测试用例和套件的名称和状态是用 相当于python内置函数repr的逻辑。
额外费用
对于与Depends on test failure对称,关键字Depends on test success可用作Depends on test:
*** Test cases ***This Test Depends on "Passing Test" Passing (using alternate keyword)Depends on test successPassing TestLogThe rest of the keywords in this test will run as normal.