我是黄瓜世界的新手,我只想针对我的情况描述一个汇总。我有一个类似下面的模型和一个DataTransferObject,我想编写一个返回JSON的REST Api。
public class Product {
int id;
String name;
double basePrice;
ProductCategory category;
}
public class ProductCategory {
int id;
String name;
List<Customization> possibleCustomizationsForCategory;
}
public class Customization {
int id;
String characteristic;
double additionalPrice;
}
public class ProductDTO {
int productId;
String productName;
double basePrice;
Size size;
int productCategoryId;
String productCategoryName;
List<Integer> possibleCustomizationIds;
}
我想写这样的东西:
Given the system has persisted the following products
When a client requests GET /products
Then he will receive a JSON like the following:
"""
[
{
"productId": 1,
"productName": "Kaffee",
"basePrice": 2.00,
"size": "SMALL",
"productCategoryId": 1,
"productCategoryName": "Hot Drinks",
"possibleCustomizationIds": [1,2,3,4,5,6]
},
{
"productId": 2,
"productName": "Kaffee",
"basePrice": 3.0,
"size": "MEDIUM",
"productCategoryId": 1,
"productCategoryName": "Hot Drinks",
"possibleCustomizationIds": [1,2,3,4,5,6]
}
{
"productId": 3,
"productName": "Cookie",
"basePrice": 1.0,
"size": "SMALL",
"productCategoryId": 1,
"productCategoryName": "Biscuite",
"possibleCustomizationIds": [8,9]
}
]
"""
但是我该如何编写给定部分并描述对象,从而清楚地知道存在三种不同的聚合类?
答案 0 :(得分:0)
我将让Gherkin使用更具业务水平的语言来描述您要解决的问题。
然后,我将用步骤定义描述问题的解决方案。
因此,您的嫩黄瓜可能是:
Given the following products are in stock
| Product |
| Small Kaffee |
| Medium Kaffee |
| Small Cookie |
When I get a list of stock
Then I the three products should be shown as in stock
And I should be able to view the details about them
我假设这是库存控制情况。然后,可以针对数据库,Web API或GUI运行此方案,并且应该仍然适用,只是采用了不同的解决方案,即使用不同的步骤定义。