I am implementing this test class taken from http://www.lucassaldanha.com/unit-and-integration-tests-in-spring-boot/
My IDE (Intellij) is not resolving the .andExpect() method. I've searched the web but cannot find which jar or class this is part of. Can anyone help me out? Thank you.
@RunWith(SpringRunner.class)
public class ClientControllerTest {
@Autowired
MockMvc mockMvc;
@MockBean
CreateClientService createClientServiceMock;
@Autowired
ObjectMapper objectMapper;
@Test
public void testCreateClientSuccessfully() throws Exception {
given(createClientServiceMock.createClient("Foo")).willReturn(new Client("Foo"));
mockMvc.perform(post("/clients")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsBytes(new CreateClientRequest("Foo"))))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.name", is("Foo")))
.andExpect(jsonPath("$.number", notNullValue()));
}
...
}
I understand that this is a very old thread, but in case anyone else runs into the same issue here's an answer. andExpect() needs to be moved outside of the perform() function's closing brackets.
It's part of spring test framework.
Implements interface org.springframework.test.web.servlet.ResultActions
Maven artifact : Maven central
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With