springboot单元测试

单元测试步骤

  1. 添加依赖

        

            org.springframework.boot

            spring-boot-starter-test

            test

        

  1. 添加测试父类

指定启动类,端口随机


@RunWith(SpringRunner.class)

@SpringBootTest(classes = WksixApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class WksixApplicationTests {

    @Test

    public void contextLoads() {

    }

}

  1. 测试具体service,只要继承上面的测试父类即可

public class ArticleServiceImplTest extends WksixApplicationTests {

    @Autowired

    ArticleService articleService;

    @Test

    public void test(){

        articleService.testTransaction();

    }

}

@Test 导入的是 org.junit.Test

你可能感兴趣的:(springboot单元测试)