我正在尝试测试 aUnitTest但java.lang.AssertionError: Response content
在运行测试时得到了。
我的日志
java.lang.AssertionError: Response content
Expected: <[UserDTO [firstName=Ahmad, lastName=shahzad, userName=1, emailAddress=ahmad.shahzad@null], UserDTO [firstName=Jamshaid, lastName=iqbal, userName=2, emailAddress=jamshaid.ali@null], UserDTO [firstName=Waqas, lastName=Akram, userName=3, emailAddress=waqas.akram@null]]>
but: was "[{\"firstName\":\"Ahmad\",\"lastName\":\"shahzad\",\"userName\":\"1\",\"emailAddress\":\"ahmad.shahzad@null\"},{\"firstName\":\"Jamshaid\",\"lastName\":\"iqbal\",\"userName\":\"2\",\"emailAddress\":\"jamshaid.ali@null\"},{\"firstName\":\"Waqas\",\"lastName\":\"Akram\",\"userName\":\"3\",\"emailAddress\":\"waqas.akram@null\"}]"
Expected :<[UserDTO [firstName=Ahmad, lastName=shahzad, userName=1, emailAddress=ahmad.shahzad@null], UserDTO [firstName=Jamshaid, lastName=iqbal, userName=2, emailAddress=jamshaid.ali@null], UserDTO [firstName=Waqas, lastName=Akram, userName=3, emailAddress=waqas.akram@null]]>
Actual :"[{\"firstName\":\"Ahmad\",\"lastName\":\"shahzad\",\"userName\":\"1\",\"emailAddress\":\"ahmad.shahzad@null\"},{\"firstName\":\"Jamshaid\",\"lastName\":\"iqbal\",\"userName\":\"2\",\"emailAddress\":\"jamshaid.ali@null\"},{\"firstName\":\"Waqas\",\"lastName\":\"Akram\",\"userName\":\"3\",\"emailAddress\":\"waqas.akram@null\"}]"
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.springframework.test.web.servlet.result.ContentResultMatchers.lambda$string$3(ContentResultMatchers.java:130)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:195)
单元测试用例类
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class UnitTestAuth {
@Autowired
public MockMvc mvc;
@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/auth").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo(new UserController().getUsers())));
}
}
不负相思意
叮当猫咪
相关分类