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
    
        }

    }

}

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