行为 - 使用空白示例字段进行测试
Behave - Testing using blank Example fields
我正在使用 Behave 自动测试配置文件,作为此测试的一部分,我需要使用无效字段和空白字段填充配置文件中的各个字段。在我输入值的地方,我可以使用场景大纲在示例中输入值来完成此操作。但是,当我尝试使用此方法输入空白字段时,行为不喜欢没有价值的事实。
是否有一种简单的方法可以从示例文件中传递空白值,或者我是否需要使用单独的行为测试来测试这些条件
feature
Scenario Outline:Misconfigured Identity Listener
Given an already stopped Identity Listener
And parameter <parameter> is configured to value <config_value>
When the Identity Listener is started
Then the identity listener process is not present on the system
And the log contains a <message> showing that the parameter is not configured
Examples: Protocols
|parameter |message |config_value|
|cache_ip_address | cache_ip_address | |
|cache_ip_address | cache_ip_address | 123.123.12 |
我定义配置值的步骤
@given('parameter {parameter} is configured to value {config_value}')
def step_impl(context, parameter, config_value):
context.parameter = parameter
context.config_value = config_value
context.identity_listener.update_config(parameter, config_value)
使用 sed -i 更改配置文件(我在这个测试中与 linux 框交互)
def update_config(self, param, config_value):
command = 'sudo sh -c "sed -i'
command = command + " '/" + param + "/c\" + param + "= "+ config_value + " \' {0}\""
command = command.format(self.config_file)
self.il_ssh.runcmd(command)
感谢@Verv 的回答,我在下面得到了这个可行的解决方案
在我不想传递值的字段中传递了一个空值
|parameter |message |config_value|
|cache_ip_address | cache_ip_address | empty |
在我的更新配置步骤中添加了 if else 语句
def update_config(self, param, config_value):
if config_value == "empty":
il_config = ""
else:
il_config = config_value
command = 'sudo sh -c "sed -i'
command = command + " '/" + param + "/c\" + param + "= " + il_config + " \' {0}\""
command = command.format(self.config_file)
self.il_ssh.runcmd(command)
您可以在字段中放置类似 empty
的内容,并调整您的方法,以便每当字段的值为 empty
时,您将其视为实际的空字符串(即 ""
)
我正在使用 Behave 自动测试配置文件,作为此测试的一部分,我需要使用无效字段和空白字段填充配置文件中的各个字段。在我输入值的地方,我可以使用场景大纲在示例中输入值来完成此操作。但是,当我尝试使用此方法输入空白字段时,行为不喜欢没有价值的事实。
是否有一种简单的方法可以从示例文件中传递空白值,或者我是否需要使用单独的行为测试来测试这些条件
feature
Scenario Outline:Misconfigured Identity Listener
Given an already stopped Identity Listener
And parameter <parameter> is configured to value <config_value>
When the Identity Listener is started
Then the identity listener process is not present on the system
And the log contains a <message> showing that the parameter is not configured
Examples: Protocols
|parameter |message |config_value|
|cache_ip_address | cache_ip_address | |
|cache_ip_address | cache_ip_address | 123.123.12 |
我定义配置值的步骤
@given('parameter {parameter} is configured to value {config_value}')
def step_impl(context, parameter, config_value):
context.parameter = parameter
context.config_value = config_value
context.identity_listener.update_config(parameter, config_value)
使用 sed -i 更改配置文件(我在这个测试中与 linux 框交互)
def update_config(self, param, config_value):
command = 'sudo sh -c "sed -i'
command = command + " '/" + param + "/c\" + param + "= "+ config_value + " \' {0}\""
command = command.format(self.config_file)
self.il_ssh.runcmd(command)
感谢@Verv 的回答,我在下面得到了这个可行的解决方案
在我不想传递值的字段中传递了一个空值
|parameter |message |config_value|
|cache_ip_address | cache_ip_address | empty |
在我的更新配置步骤中添加了 if else 语句
def update_config(self, param, config_value):
if config_value == "empty":
il_config = ""
else:
il_config = config_value
command = 'sudo sh -c "sed -i'
command = command + " '/" + param + "/c\" + param + "= " + il_config + " \' {0}\""
command = command.format(self.config_file)
self.il_ssh.runcmd(command)
您可以在字段中放置类似 empty
的内容,并调整您的方法,以便每当字段的值为 empty
时,您将其视为实际的空字符串(即 ""
)