zoukankan      html  css  js  c++  java
  • Spring Boot 进阶之Web进阶 学习

    可在类文件中,右键->GO TO->Test 自动生成测试文件

    1.添加测试注解

      简单方法测试

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class GirlServiceTest {
    @Autowired
    private GirlService girlService;

    @Test
    public void findOne() throws Exception {
    Girl girl = girlService.findOne(30);
    Assert.assertEquals(new Integer(12),girl.getAge()); //断言
    }
    }

    restapi测试
    @RunWith(SpringRunner.class)
    @SpringBootTest
    @AutoConfigureMockMvc
    public class GirlControllerTest {
    @Autowired
    private MockMvc mvc;

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

    }

    打包命令, cd girls
         mvn clean package //打包过程中执行单元测试
         mvn clean package -Dmaven.test.skip=true //打包过程中,跳过单元测试
  • 相关阅读:
    VSCODE极简配置(备份)
    顺时针打印矩阵--剑指offer
    回文链表 leetcode
    E
    E. Kleofáš and the n-thlon
    单调栈板子
    D
    CodeForces 600E Lomsat gelral(线段树合并)
    C# 面试宝典
    JavaScript 火花效果
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/8946103.html
Copyright © 2011-2022 走看看