1
jsonPathのすべてが私のコントローラに適しているかどうか検証するのに問題があります。私はテストエリアが初めてで、紹介サイトを利用していますが、デザインには非常に特徴的なものがたくさんあるため、いくつかの回答を見つけるのは難しいです。誰かが私を助けることができれば、私は感謝するでしょう。コード:テストJunitとMockitoは日付を時間で分析するとエラーが表示されます
package test
public class FormControllerTest {
private MockMvc mockMvc;
@Mock
private FormServiceImpl formService;
@Mock
private UserServiceImpl userService;
@InjectMocks
private FormController formController;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders
.standaloneSetup(formController)
.build();
}
がテスト:そして、それは実行の終わりに2時間を追加し
java.lang.AssertionError: JSON path "$.dateInit" Expected: is Tue (Jan 03 02:00:02 BRST 2017) but: was "2017-01-03 04:00:02"
@Test
public void test_get_Form_success() throws Exception {
SimpleDateFormat formato = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
Date data = formato.parse("2017-01-03 02:00:02");
Date data2 = formato.parse("2017-01-05 02:00:02");
Form form = new Form().id(1).name("formTest")
.active(true).description("Formtesting")
.dateInit(data).dateEnd(data2);
//List<Form> forms = Arrays.asList(form.dateInit(data).dateEnd(data2));
//System.out.println(form.getDateEnd());
when(formService.findOneForm(form.getId())).thenReturn(form);
mockMvc.perform(get("/form/{id}",form.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.id", is(1)))
.andExpect(jsonPath("$.name", is("formTest")))
.andExpect(jsonPath("$.active", is(true)))
.andExpect(jsonPath("$.description", is("Formtesting")))
.andExpect(jsonPath("$.dateInit", is(form.getDateInit())))
.andExpect(jsonPath("$.dateEnd", is(form.getDateEnd())));
verify(formService, times(2)).findOneForm(form.getId());
verifyNoMoreInteractions(formService);
}
エラー、どのようにこの問題を解決するには?
は私が変更されているが、それはまだ同じエラーを持っています、私は何をすべき? –