我是黄瓜世界的新手,我只想为我的场景描述一个聚合。我有一个模型和一个类似下面的DataTransferObject,我想写一个REST Api,它返回一个JSON。
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]
}
]
"""但是,我如何编写给定的部分并以一种明确的方式描述对象,即存在三个带有聚合的不同类?
发布于 2018-11-06 23:03:53
我会让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运行,并且应该仍然正确,只是需要一个不同的解决方案。即使用不同的步骤定义。
https://stackoverflow.com/questions/53005451
复制相似问题