小编use*_*742的帖子

无法解析 .andExpect() 方法

我正在实施从http://www.lucassaldanha.com/unit-and-integration-tests-in-spring-boot/获取的这个测试类

我的 IDE (Intellij) 没有解析 .andExpect() 方法。我在网上搜索过,但找不到这是哪个 jar 或类的一部分。谁能帮我吗?谢谢你。

@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()));
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

java testing rest spring intellij-idea

4
推荐指数
1
解决办法
3683
查看次数

标签 统计

intellij-idea ×1

java ×1

rest ×1

spring ×1

testing ×1