Maven依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
例子
@RunWith(SpringRunner.class)
@SpringBootTest(classes = XXXApplication.class)
@WebAppConfiguration
public class RecordControllerTest extends BaseTest {
@Autowired
WebApplicationContext webApplicationContext;
@Override
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void createRecord() throws Exception {
RequestBuilder request = MockMvcRequestBuilders.get("/record/create")
.param("scriptId", "cb_order")
.param("isDynamic", "true");
this.mockMvc.perform(request)
.andDo(print())
.andExpect(status().isOk());
}
}