在运行提供程序测试(Spring Boot)API 时,是否可以使用带有 json 示例的 _data 文件夹,就像使用存根测试一样?
我有一个 quote-api.yaml 合约 src/test/contracts/quote-api.yml
我创建了一个文件夹 src/测试/合同/quote-api_data 并将文件 happy_path.json 放在那里。
我在那里放置了以下json
{
"http-request": {
"method": "POST",
"path" : "/quote",
"body" : {
"quoteReference": "VALID_QUOTE_REFERENCE",
"customers": [
{
"customerType": "Z",
"dateOfBirth" : "2000-01-01"
},
{
"customerType": "Z",
"dateOfBirth" : "2001-01-01"
}
]
}
},
"http-response": {
"status" : 200,
"body" : {
"fullPrice": 10.0,
"monthlyPrice": 20.0,
"quoteStatus": "OK"
}
}
}
我的 ContractTests 看起来像
public class ContractTest extends SpecmaticJUnitSupport {
private static ConfigurableApplicationContext context;
@BeforeAll
public static void setUp() {
System.setProperty("host", "localhost");
System.setProperty("port", "8080");
System.setProperty("contractPaths", "src\\test\\contracts\\quotes.yaml");
// System.setProperty("SPECMATIC_GENERATIVE_TESTS", "true");
context = SpringApplication.run(HomeownerapiApplication.class);
}
@AfterAll
public static void tearDown() {
context.close();
}
}
当我在 Intellij 中运行 ContractTests 时,它似乎没有获取 happy_path.json 文件?
运行 API(提供者)测试时是否必须使用 .spec 文件来外部化示例? 如果在上面的示例中是这样,您知道我如何表示上面 json 中提供的客户数组吗?
谢谢, 马克。