亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在多模塊項目中使用 JUnit5 和 SpringBoot2 通過 gradle

如何在多模塊項目中使用 JUnit5 和 SpringBoot2 通過 gradle

小怪獸愛吃肉 2023-09-13 15:25:21
我創建了一個空的 gradle 項目,內部包含單個模塊(子項目),也作為 gradle 項目,但使用 Spring boot 2。主要(無標題1)build.gradle:group 'com.example'version '1.0-SNAPSHOT'allprojects {    repositories {        mavenCentral()    }}設置.gradle:rootProject.name = 'main-project'include 'new-one'子項目(新項目):構建 gradle:plugins {    id("java")    id("org.springframework.boot") version "2.1.8.RELEASE"    id("io.spring.dependency-management") version "1.0.8.RELEASE"}group = 'com.example'version '1.0-SNAPSHOT'sourceCompatibility = 1.12dependencies {    implementation 'org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE'    implementation 'org.springframework.boot:spring-boot-starter-web'    testImplementation 'org.springframework.boot:spring-boot-starter-test'    def junit = '5.5.2'    testImplementation ("org.junit.jupiter:junit-jupiter-api:${junit}")    testImplementation ("org.junit.jupiter:junit-jupiter-params:${junit}")    testImplementation ("org.assertj:assertj-core:3.11.1")    testRuntime("org.junit.jupiter:junit-jupiter-engine:${junit}")}test {    useJUnitPlatform()}使用測試運行器運行測試:IntelliJ idea 編譯并通過測試,但是當我使用 gradle 時,如果我運行單個測試,它會返回:Testing started at 2:48 PM ...> Task :new-one:cleanTest> Task :new-one:compileJava UP-TO-DATE> Task :new-one:processResources NO-SOURCE> Task :new-one:classes UP-TO-DATE> Task :new-one:compileTestJava> Task :new-one:processTestResources NO-SOURCE> Task :new-one:testClasses> Task :new-one:test FAILEDSep 30, 2019 2:48:53 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowableWARNING: TestEngine with ID 'junit-jupiter' failed to discover testsjava.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/Sel
查看完整描述

1 回答

?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

如https://github.com/junit-team/junit5-samples/blob/r5.5.2/junit5-jupiter-starter-gradle/build.gradle所示,我建議將 Jupiter 依賴項定義為:

testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')

希望能解決這個問題。


查看完整回答
反對 回復 2023-09-13
  • 1 回答
  • 0 關注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號