JUnit5 整合指南

2021-08-27 18:01:29 字數 1954 閱讀 2997

junit之前的版本是乙個整體,而junit5與其不同,它是由幾個不同的模組組成,而這些模組分別來自三個不同的子專案中。在官方文件中,給出了這麼乙個junit5的等式:

junit 5 = junit platform + junit jupiter + junit vintage

junit jupiter 是乙個組合體,它是由在junit 5中編寫測試和擴充套件的新 程式設計模型 和 擴充套件模型 組成。另外,jupiter子專案還提供了乙個testengine,用於在平台上執行基於jupiter的測試。

junit vintage 提供了乙個testengine,用於在平台上執行基於junit 3和junit 4的測試。

在不同的模組中,又生成了不同的子元件,以用於依賴。在新增依賴關係時,並不需要新增所有的子元件,只需要新增所需的子元件即可。

// junit

// org.junit.platform

testimplementation 'org.junit.platform:junit-platform-launcher:1.2.0'

testimplementation 'org.junit.platform:junit-platform-console:1.2.0'

testimplementation 'org.junit.platform:junit-platform-console-standalone:1.2.0'

testimplementation 'org.junit.platform:junit-platform-engine:1.2.0'

testimplementation 'org.junit.platform:junit-platform-gradle-plugin:1.2.0'

testimplementation 'org.junit.platform:junit-platform-runner:1.2.0'

testimplementation 'org.junit.platform:junit-platform-suite-api:1.2.0'

testimplementation 'org.junit.platform:junit-platform-surefire-provider:1.2.0'

// org.junit.jupiter

testimplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'

testruntimeonly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'

testruntimeonly 'org.junit.jupiter:junit-jupiter-params:5.2.0'

testruntimeonly 'org.junit.jupiter:junit-jupiter-migration-support:5.2.0'

// org.junit.vintage

testruntimeonly 'org.junit.vintage:junit-vintage-engine:5.2.0'

import static org.junit

.jupiter

.api

.assertions

.assertequals

;import org.junit

.jupiter

.api

.test

;class firsttests

}

在上面的測試用例中:

使用myfirsttest方法上方使用@test方法,表明該方法是乙個測試方法。

myfirsttest方法中,使用斷言assertequals,用以驗證21+1的值是否相等

Lua5整合指南 1

第一章先開個頭 看不明白的話也不要緊,下一章將從怎麼編譯介紹起。源 閱讀貴在堅持,當然有乙個好工具也是必要的。推薦大家使用source insight 這是乙個非常好用的東西。不管是閱讀還是寫c c c 的 使用它都會感覺非常爽!今天開始閱讀,因為是開頭,所以選擇乙個簡單的檔案 etc min.c ...

Spring5t整合JUnit5的單元測試

spring 5 全面接納了函式式範例,並支援 junit 5 及其新的函式式測試風格。還提供了對 junit 4 的向後相容性,以確保不會破壞舊 匯入依賴 org.junit.jupitergroupid junit jupiterartifactid releaseversion testsco...

Spring筆記 4 整合Junit

在測試類中.每個測試方法都有以下 new bean.xml iaccountservice as ac.getbean accountservice iaccountservice.class 這兩行 的作用是獲取容器,如果不寫的話,直接會提示空指標異常。所以又不能輕易刪掉。上述問題的解決方法 讓s...