大家好,我想知道我是不是在遵循最佳实践。
我有如下的步骤定义
public class StepDefinitions {
@DataTableType
public Author authorEntry(Map<String, String> entry) {
return new Author(
entry.get("firstName"),
entry.get("lastName"),
entry.get("famousBook"));
}
@Given("There are my favorite authors")
public void these_are_my_favourite_authors(List<Author> authors) {
// step implementation
}
}
然后我的特征文件可能是这样的
Feature: this is a feature
Scenario: this is a scenario
Given There are my favorite authors
|firstName| lastName |
| first | last |
Scenario: this is another scenario
Given There are my favorite authors
|firstName| lastName | famousBook |
| first | last | book |
因此,在第一步中,它将创建一个Author对象,但使用famousBook == null。
由于我正在创建用于REST请求的对象,而jackson将忽略空值,所以可以像这样创建对象吗?
发布于 2021-12-02 15:54:14
您在示例中使用了错误的数据结构。您可以参考这个resource,给出不同表类型的示例。
在您的示例中,有一张表
|firstName| lastName |
| first | last |
并尝试将其解析为Map<String, String> entry
,这将产生以下映射:
[key1 = firstName, value1 = lastName]
[key2 = first, value2 = last]
如果您需要将其视为第一行中的标题,则需要将其解析为List<Map<String, String>>
https://stackoverflow.com/questions/70182686
复制相似问题