springboot项目中单元测试类编写

1、pom.xml 添加jar

<!-- 测试类 -->

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-test</artifactId>

    <scope>test</scope>

</dependency>

 

2、创建测试类,注:Application.class 为启动类

@RunWith(SpringRunner.class)

@SpringBootTest(classes = {Application.class})

public class MethodTests {

    @Test

    public void contextLoads() {

        try {

            

        } catch (Exception e) {

        // TODO: handle exception
    
        }

    }

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章