国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【SpringBoot】org.junit.runners.model.InvalidTestClassError 單元測試類報錯(已解決)

這篇具有很好參考價值的文章主要介紹了【SpringBoot】org.junit.runners.model.InvalidTestClassError 單元測試類報錯(已解決)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

解決問題

出現(xiàn)該報錯是因為 @Test 注解的錯誤使用。

@Test 注解的正確使用 :

  1. 權(quán)限必須是public
  2. 不能有參數(shù)
  3. 返回值類型是void
  4. 本類的其他的使用了Test注解的方法返回值也必須是void
  5. 正確導(dǎo)包 import org.junit.Test

一般正確使用 @Test 下,就沒有報錯了。


深入探討

但是,我們可以繼續(xù)深入探討。

SpringBootApplication 對應(yīng)的測試類

import org.junit.jupiter.api.Test;
@SpringBootTest
class EzyUserBackendApplicationTests {

    @Resource
    private UserMapper userMapper;

    @Test
    void contextLoads() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
        Assert.assertEquals(5, userList.size());
        userList.forEach(System.out::println);
    }

}

正常運(yùn)行。

如果換成:

import org.junit.Test;

則不能啟動。

普通的一個測試類

import org.junit.Test;
import org.junit.runner.RunWith;
@SpringBootTest
@RunWith(SpringRunner.class)
public class SampleTest {
    @Resource
    private UserMapper userMapper;

    @Test
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
        Assert.assertEquals(5, userList.size());
        userList.forEach(System.out::println);
    }
}

正常啟動。

或者這樣:

import org.junit.jupiter.api.Test;
@SpringBootTest
public class SampleTest {
    @Resource
    private UserMapper userMapper;

    @Test
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
        Assert.assertEquals(5, userList.size());
        userList.forEach(System.out::println);
    }
}

也會正常啟動。文章來源地址http://www.zghlxwxcb.cn/news/detail-789848.html

到了這里,關(guān)于【SpringBoot】org.junit.runners.model.InvalidTestClassError 單元測試類報錯(已解決)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【SpringBoot】mockito+junit 單元測試

    【SpringBoot】mockito+junit 單元測試

    CommonServiceImpl 在方法 getSourceCodeMap() 調(diào)用了 ServiceA 的方法 list(QueryBO queryBo) 。 org.mockito.exceptions.base.MockitoException: No tests found in ClientSyncServiceImplTest Is the method annotated with @Test? Is the method public? 解決方案: Test引入 org.junit.Test 不要引入 org.junit.jupiter.api.Test 例如獲取當(dāng)前用戶 moc

    2024年02月09日
    瀏覽(30)
  • springboot Junit單元測試默認(rèn)事務(wù)不提交

    因為以前總覺得Junit單元測試配置比較繁瑣,代碼功能大多使用main方法或者postman測試,直到最近才使用單元測試,在測試過程中遇到了事務(wù)不提交的問題,一直以為是代碼問題,后來才直到單元測試 默認(rèn)不提交事務(wù) ,記錄下來,防止以后再次踩坑。 如上,入庫操作不會實(shí)現(xiàn)

    2024年02月10日
    瀏覽(22)
  • SpringBoot 中如何利用 Junit 實(shí)現(xiàn)單元測試?

    SpringBoot 中如何利用 Junit 實(shí)現(xiàn)單元測試?

    2024軟件測試面試刷題,這個小程序(永久刷題),靠它快速找到工作了?。ㄋ㈩}APP的天花板)_軟件測試刷題小程序-CSDN博客 文章瀏覽閱讀2.5k次,點(diǎn)贊85次,收藏11次。你知不知道有這么一個軟件測試面試的刷題小程序。里面包含了面試常問的軟件測試基礎(chǔ)題,web自動化測試、

    2024年03月11日
    瀏覽(24)
  • junit單元測試 mybatis 單獨(dú)測試 springboot

    目錄 省流: 正文 一、直接測(無需配置掃描和xml) 1. 場景 2. 無需配置掃描,直接在測試類注入Mapper 3. 報錯 補(bǔ)充: 關(guān)于@RunWith 常見的報錯: 1.包名不同導(dǎo)致報錯 test目錄下配置文件:application.yml中配置數(shù)據(jù)庫信息。 test目錄下各類:直接寫測試類即可,直接調(diào)用main目錄下各

    2024年02月07日
    瀏覽(25)
  • SpringBoot2---單元測試(Junit5)(1)

    SpringBoot2---單元測試(Junit5)(1)

    org.junit.vintage junit-vintage-engine test org.hamcrest hamcrest-core org.springframework.boot spring-boot-starter-test test 現(xiàn)在版本: @SpringBootTest class Boot05WebAdminApplicationTests { @Test void contextLoads() { } } 以前: @SpringBootTest + @RunWith(SpringRunner.class) SpringBoot整合Junit以后。 編寫測試方法:@Test標(biāo)注(注意需要

    2024年04月29日
    瀏覽(17)
  • 13.Springboot整合junit5單元測試與生成單元測試覆蓋率

    13.Springboot整合junit5單元測試與生成單元測試覆蓋率

    現(xiàn)在基本大公司都要求單元測試了,保證我們代碼得質(zhì)量,而我司更是要求覆蓋率要達(dá)到60%以上,所以搞一下。 這里有兩個方法: 1.使用maven自帶得test,idea右側(cè)maven模塊執(zhí)行項目下得test 2.使用cmd命令,在你的項目pom文件所在目錄 ,打開cmd,執(zhí)行如下: 結(jié)果如下:打開site文

    2024年02月16日
    瀏覽(23)
  • SpringBoot單元測試--Mockito+Junit5框架使用

    SpringBoot單元測試--Mockito+Junit5框架使用

    作為程序員為了提前發(fā)現(xiàn)代碼bug,優(yōu)化代碼; 通常我們寫完某個功能模塊代碼后都需要寫單元測試對代碼塊進(jìn)行測試(特別是敏捷開發(fā)中);Java項目最常用的單元測試框架即為Junit(目前最新版本為Junit5),SpringBoot本身也整合了該框架。在寫單元測試時代碼塊中的調(diào)到第三方接口方

    2024年02月02日
    瀏覽(22)
  • 靜態(tài)方法 單元測試 springboot+mokito+junit5

    CodecUtils的方法是靜態(tài)類,使用@InjectMocks不能有用,因為這個注解只能用于非靜態(tài)的對象。 想要為靜態(tài)方法寫單元測試,可以使用Mockito.mockStatic(Class classToMock)方法,它可以返回一個MockedStatic對象,用于模擬靜態(tài)方法的調(diào)用。 1.導(dǎo)入依賴 2.單元測試 可以參考如下地址,了解如何

    2024年04月25日
    瀏覽(20)
  • SpringBoot測試(Junit單元測試、MockMvc測試Http請求 )

    SpringBoot測試(Junit單元測試、MockMvc測試Http請求 )

    Java知識點(diǎn)總結(jié):想看的可以從這里進(jìn)入 2.13、測試 測試就是在開發(fā)過程中用來檢測某一段代碼的功能是否能正確執(zhí)行,Spring Boot 項?創(chuàng)建時會默認(rèn)單元測試框架 spring-boot-test,它Spring Test、JUnit等其他測試框架結(jié)合起來(JUnit 5、AssertJ、Hamcrest、Mockito、JSONassert、JsonPath、Spring

    2024年02月06日
    瀏覽(49)
  • junit單元測試mock常用寫法-springboot與springmvc

    做單元測試時候,經(jīng)常會mock一些方法,得到期望的返回值,這里記錄一下常見的public、private、static方法,以及設(shè)計到的內(nèi)部調(diào)用的方法 這里采用maven,引入powermock即可 所有單元測試的測試類都繼成BaseTest即可 (1)springboot的示例 (2)springmvc的示例 有如下類需要編寫單元測

    2024年02月02日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包