3
我編寫了一個在Intellij中成功執行的JUnit測試,並且它已通過。但是,如果我運行mvn clean test,那麼特定的測試失敗。更具體的任務是檢查請求是否被髮送。所以當我在IntelliJ中運行測試時,測試通過狀態碼201(成功)。但是當我運行mvn clean install時,它顯示爲狀態碼400(錯誤的請求)。JUnit測試在IntelliJ中成功,但在Maven中失敗
我在網上搜索了這個,但找不到解決方案。請幫幫我。
以下是代碼。它未能在第一斷言:assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
:
@Test
public void testUpdateMultiValueAttributes() throws URISyntaxException {
String createPayload =
"{\n" +
" \"id\": 9,\n" +
" \"email\": \"" + "[email protected]" + "\",\n" +
" \"profile\": {\"userAttrs\":[" +
" {\"CUST_ATTR_MULTI_VALUE\": \"CUST_ATTR_MULTI_VALUE_3\"}" +
" ]}" +
"}";
MockHttpRequest request = MockHttpRequest.put("/subscribers/9");
request.contentType(MediaType.APPLICATION_JSON);
request.content(createPayload.getBytes());
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
LOG.error(response.getContentAsString());
response.toString();
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
SubscriberDto subscriber = null ;
try {
subscriber = MarshallingUtils.unmarshallJSON(new TypeReference<SubscriberDto>() {
}, response.getContentAsString());
} catch (Exception e) {
fail(e.getMessage());
}
Collection<SubscriberAttributeDto> customAttributes = subscriber.getProfile().getUserAttrs();
if (customAttributes!=null)
assertTrue(customAttributes.contains(new SubscriberAttributeDto("CUST_ATTR_MULTI_VALUE", "CUST_ATTR_MULTI_VALUE_3")));
你可以給一些更多的信息?代碼片段等 – boskop
您在%PATH%中的Java版本是否與您在IDE中使用的版本不同? – JustinKSU
如果您需要其他任何東西,請讓我知道 –