0
点赞
收藏
分享

微信扫一扫

SpringBoot - 单元测试


对Service的Test

  • pom.xml引入junit
  • 加注解:
  • @RunWith(SpringRunner.class)
  • @SpringBootTest
  • @Test

对Controller的Test

  • @RunWith(SpringRunner.class)
  • @SpringBootTest
  • @AutoConfigureMockMvc
  • @Test
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class GrilController {

@Autowired
private MockMvc mvc;

@Test
public void girlList() throws Exception {
mvc.perform(
MockMvcRequestBuilders.get("/girl/girls"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().string("abc"));
}
}

批量 / 跳过单元测试

  • 批量测试:只需要打包即可,就会进行批量测试,并显示结果
    SpringBoot - 单元测试_批量测试
  • 跳过测试:mvn clean package -Dmaven.test.skip=true
    SpringBoot - 单元测试_单元测试_02


举报

相关推荐

0 条评论