我有一個 Spring Boot v1.5.14.RELEASE 應用程序,使用 Spring Initializer、JPA、嵌入式 Tomcat 并遵循 RESTful API 架構原則。我創建了這個測試@Test public void createCustomerChain() throws Exception { this.mockMvc.perform(post("/customer/createCustomer") .contentType(MediaType.APPLICATION_JSON_VALUE) .content("{\n" + " \"subSegment\":\"25\",\n" + " \"legalLanguage\":\"NL\",\n" + " \"isRestrictel\":true,\n" + " \"isCommunicationLanguageForAllAccount\":true,\n" + " \"isAntiMarketing\":true,\n" + " \"hotelChain\":{\n" + " \"legalForm\":\"09\",\n" + " \"foundationDate\":\"2001-12-17T09:30:47Z\",\n" + " \"tradingName\":\"COMPANY NAME\",\n" + " \"printName\":\"TEST PRINT\",\n" + " \"naceCode\":\"16230\",\n" + " \"vatNumber\":\"41223334343\", \n" + " \"countryVatCode\":\"IN\",\n" + " \"isSubjectToVAT\":true,\n" + " \"sectorCode\":\"85\",\n" + " \"legalAddress\": {\n" + " \"mainkey\":2088512,\n" + " \"subkey\":3256\n" + }這是運行測試的結果:org.springframework.restdocs.snippet.SnippetException: Fields with the following paths were not found in the payload: [customerId]customerId并從測試中刪除fieldWithPath成功通過但是,我想知道為什么我對這樣的字段沒有相同的錯誤billingAccountId
1 回答

當年話下
TA貢獻1890條經驗 獲得超9個贊
這是由于在某些情況下customerId
可能存在null
或不存在字段。您可以使用optional
它:
fieldWithPath("customerId").description("Description").optional()
為了找到更準確的原因,請發布該createCustomer()
方法的代碼。
添加回答
舉報
0/150
提交
取消