Springboot的Test單元測(cè)試操作
簡(jiǎn)單總結(jié)需要操作的步驟
1,導(dǎo)入依賴(lài)
2,創(chuàng)建目錄(目錄和啟動(dòng)類(lèi)的目錄保持一致)
3,添加注解
4,寫(xiě)方法測(cè)試
1,導(dǎo)入依賴(lài)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-858140.html
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
2,創(chuàng)建目錄(目錄和啟動(dòng)類(lèi)的目錄保持一致),并test目錄綠色標(biāo)記一下
3,添加注解
注意的是,這里的test的類(lèi)路徑import org.junit.Test;,idea自動(dòng)導(dǎo)入可能是導(dǎo)入其他導(dǎo)致報(bào)錯(cuò),這里注意一下就可以了文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-858140.html
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@RunWith(SpringRunner.class)
public class PerdTest {
@Test
public void pageTest(){
}
}
到了這里,關(guān)于Springboot的Test單元測(cè)試操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!