SpringBoot-整合junt5

导入依赖启动器

springboot初始化器默认导入junit5
在这里插入图片描述在这里插入图片描述
常用测试注解

@SpringBootTest//如果标注这个 测试无法使用springboot的自动注入
/**
 * springboot junit的单元的测试
 */
@DisplayName("junit5测试类")
class JiaqiselflearnApplicationTests {
    @Autowired
  private deptMapper deptmapper;
    @Test
    void contextLoads() {
        System.out.println(deptmapper);
    }

    @Test
    public void test(){
        int conuntall = deptmapper.conuntall();
        System.out.println(conuntall);
    }
    @Transactional//标注测试方法会自动回滚数据
    @Test//junt5的Test注解
    public void test2(){
        System.out.println("测试start");
    }
    @DisplayName("测试display注解")//测试方法命名
    @Test
    public  void testjunit5(){
        System.out.println(1);
    }
    @BeforeEach//每个测试方法开始前使用
    public void testbeaforeeach(){

        System.out.println("测试就要开始了");
    }
    @AfterEach//每个测试方法测试之后执行
       public void after(){
        System.out.println("任一一个测试方法执行后开始执行");
    }
    @BeforeAll//所有方法执行前 也就是说只执行一次故此设计为static
   static void  beforeall(){
        System.out.println("所有测试都快开始了");
    }


    @AfterAll//所有方法执行前 也就是说只执行一次故此设计为static
    static void  AFTERall(){
        System.out.println("所有测试都结束");
    }
    @Timeout(value = 50,unit = TimeUnit.SECONDS)//超时值 单位
    @Test
    @DisplayName("启动所有测试")
    public  void teststartalltest(){
        test();
        test2();
        testjunit5();
        contextLoads();
    }
    /**
     *重复测试注解
     */
    @RepeatedTest(5)
    public  void testrepeat(){
        System.out.println("测试重复注解 输出5次");
    }

}

重复测试运行结果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝胖子不是胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值