springboot添加单元测试

添加依赖


        
            junit
            junit
            4.13.2
            test
        

        
            org.projectlombok
            lombok
            1.18.20
            provided
        


        
            org.springframework.boot
            spring-boot-starter-test
            test
        

启动类模块下创建测试类的目录

springboot添加单元测试_第1张图片

 创建TestMain测试类,注意:包名要和main里的包名一致

测试类添加@springbootTest注解,和RunWith注解

@SpringBootTest
@RunWith(SpringRunner.class)
public class TestMain {

    @Autowired
    private ISysRoleService roleService;


    @Test
    public void test() throws FileNotFoundException {
        roleService.deleteRoleById(1L);
    }

}

你可能感兴趣的:(单元测试,spring,boot,junit)