我有一个名为“behave”的功能,上面有很多测试。
我只需要运行特定的场景来满足开发需求。
我该怎么做?
(最好是在命令行上完成)
我只需要运行特定的场景来满足开发需求。
我该怎么做?
(最好是在命令行上完成)
-n
或--name
标志,它似乎希望在Scenario:
之后输入文本。behave -n 'This is a scenario name'
-i
或--include
标志,然后加上特性文件的名称来运行特性文件。behave -i file_name.feature
或者:
behave --include file_name
--exclude
标志来排除。behave -e file_name
pip3 install git+https://github.com/behave/behave#1.2.6rc
来解决这个问题)。Feature:
之后传入文本作为-i标志,但目前这个功能不起作用。如果它再次起作用,请有人提醒我更新。我还鼓励大家尝试使用wip标志,它允许你在测试中添加@wip
,然后-wip
不仅会运行测试,还会允许打印/记录语句进行调试。要运行单个场景,可以使用带有场景名称的-n
:
$ behave -n 'clicking the button "foo" should bar the baz'
我在上面使用单引号,以将场景名称作为-n
的一个参数。否则,shell会将场景名称的每个单词作为单独的参数传递。
behave -t '~@slow_tag_name'
2) 然而,为了最大的灵活性,我个人建议为每个场景打上一个唯一的标识符。例如,我使用一个@YYYY_MM_DD_HHmm_Initials
的标签方案,因为它足够唯一并且可追溯性很有用/有趣。然后您可以仅使用该标签来调用并运行场景,例如:
behave @2015_01_03_0936_jh
behave
非常强大的技巧:behave --wip
在开发测试时,请使用@wip
标记您的测试。除了其他提到的选择测试的方法(--name
,--tags
,--include
)之外,这将是我的第一选择,但在@Cynic的答案中仍然相当隐蔽。
你可能会对this这篇精美的文章感兴趣,它描述了如何在behave中从场景大纲中运行单个测试。
例如:
#This is Gherkin
Feature: Running a single test from a scenario outline
@scenarioGroupName @scenarioGroupName<scenarioName>
Scenario Outline: test running one of many scenarios, iteration <n> / <scenarioName>
Given test is index <n> for <scenarioName>
When we do something with <scenarioParameter>
Then all the checks pass
Examples: Test scenarios
|n | scenarioName | scenarioParameter
|1 | Able | first
|2 | Baker | second
|3 | Charlie | third
#etc
# This is shell
behave -k --tags=@scenarioGroupNameBaker
scenarioGroupNameBaker
标签。
对于每个示例行,轮廓模板标签 scenarioGroupName<scenarioName>
中的 <scenarionName>
被替换为示例行中的值,以便为每个场景行提供标签名称 :D