小黄瓜/黄瓜-如何从一个数据表中的单元格引用到另一个数据表格中的行



我想使用Cucumber来测试我的REST API。因此,我想用一些测试数据填充数据库,并在When步骤中发送GET请求。如果我能在步骤中解释数据库的状态,那就太好了。那么,有可能从数据表中的一个单元格引用到另一个表中的行吗?类似这样的东西:

Given the system knows of the following products
| productId   | productName   | productCategory |
| 1           | Kaffee        | {{HotDrinks}}   |
| 2           | Espresso      | {{HotDrink}}    |
| 3           | Hot Chocolate | {{KidsDrinks}}  |
And the system knows about the following productCategories
|                 | productCategoryId | productCategoryName  | customizations  |
| {{HotDrinks}}   | 1                 | HotDrinks            | "milk", "shots" |
| {{KidsDrinks}}  | 2                 | KidsDrinks           | "cream"         |
And the system knows about the following customizations
|               | customizationId | customizationName | kinds             |
| {{milk}}      | 1               | milk              | skim, semi, whole |
| {{shots}}     | 2               | shots             | single, double    |
| {{cream}}     | 3               | cream             | true              |
When a client requests GET /productCatalogue
Then the HTTP response status will be 200
And the response body contains the following JSON
"""
...
"""

有什么办法做这样的事吗?

您可以使用NoraUi(NoraUi,用于用户界面的NOn回归自动化,是一个基于Selenium、Cucumber和Gherkin堆栈的Java框架,用于创建GUI测试项目,这些项目可以包含在单/多应用程序web解决方案构建的连续集成链中。(

如果你不使用这个完整的交钥匙框架,你可以从他们的代码中获得灵感。在这个框架的连续集成中有一个完整的例子。在"你好"的场景中,您会发现以下步骤:

And I save the value of REST API 'GET' 'GITHUBAPI_HOME' '/search/users?q=location:rennes+language:java&page=1&per_page=10' in 'title' context key.

此步骤与此Java代码匹配(此处为完整代码(:

@And("I save the value of REST API '(.*)' '(.*)' '(.*)' in '(.*)' context key[\.|\?]")
public void saveValue(String method, String pageKey, String uri, String targetKey, List<GherkinStepCondition> conditions) throws TechnicalException, FailureException {
...
try {
json = httpService.get(Context.getUrlByPagekey(pageKey), uri);
} catch (HttpServiceException e) {
...
}
...
}

HttpService代码。此服务使用okhttp3.OkHttpClient

最新更新