SpringCoud 服務(wù)器端

2023-12-06 17:06 更新

由于您正在開發(fā)存根,因此需要確保它實際上類似于您的具體實現(xiàn)。您不能存在存根以一種方式運行而應(yīng)用程序以不同方式運行的情況,尤其是在生產(chǎn)環(huán)境中。

為了確保您的應(yīng)用程序符合您在存根中定義的方式,將從提供的存根中生成測試。

自動生成的測試或多或少看起來像這樣:

@Test
public void validate_shouldMarkClientAsFraud() throws Exception {
    // given:
        MockMvcRequestSpecification request = given()
                .header("Content-Type", "application/vnd.fraud.v1+json")
                .body("{\"client.id\":\"1234567890\",\"loanAmount\":99999}");

    // when:
        ResponseOptions response = given().spec(request)
                .put("/fraudcheck");

    // then:
        assertThat(response.statusCode()).isEqualTo(200);
        assertThat(response.header("Content-Type")).matches("application/vnd.fraud.v1.json.*");
    // and:
        DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
        assertThatJson(parsedJson).field("['fraudCheckStatus']").matches("[A-Z]{5}");
        assertThatJson(parsedJson).field("['rejection.reason']").isEqualTo("Amount too high");
}


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號