Cucumber 小黄瓜-如何从一个数据表中的单元格引用到另一个数据表中的行
我想用Cucumber来测试我的RESTAPI。 因此,我想用一些测试数据填充数据库,并在When步骤中发送GET请求。如果我能在步骤中解释数据库的状态,那就太好了。那么,是否可以将数据表中的单元格引用到另一个表中的行?大概是这样的:Cucumber 小黄瓜-如何从一个数据表中的单元格引用到另一个数据表中的行,cucumber,gherkin,cucumber-java,Cucumber,Gherkin,Cucumber Java,我想用Cucumber来测试我的RESTAPI。 因此,我想用一些测试数据填充数据库,并在When步骤中发送GET请求。如果我能在步骤中解释数据库的状态,那就太好了。那么,是否可以将数据表中的单元格引用到另一个表中的行?大概是这样的: Given the system knows of the following products | productId | productName | productCategory | | 1 | Kaffee
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,用于用户界面的非回归自动化,是一个基于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代码(完整代码)匹配:
@和(“我将REST API的值保存在“(.*)”上下文键[\\.\124;\\?]”中)
public void saveValue(字符串方法、字符串pageKey、字符串uri、字符串targetKey、列表条件)引发TechnicalException、FailureException{
...
试一试{
json=httpService.get(Context.getUrlByPagekey(pageKey),uri);
}捕获(HttpServiceException){
...
}
...
}
HttpService代码。此服务使用了
okhttp3.OkHttpClient
一个人有否决权,但肯定是错误的,因为此解决方案目前正在生产中。此外,此人没有提出更好的解决方案。
@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) {
...
}
...
}