use*_*742 4 java testing rest spring intellij-idea
我正在实施从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)
| 归档时间: |
|
| 查看次数: |
3683 次 |
| 最近记录: |