我創(chuàng)建了一個(gè)空的 gradle 項(xiàng)目,內(nèi)部包含單個(gè)模塊(子項(xiàng)目),也作為 gradle 項(xiàng)目,但使用 Spring boot 2。主要(無標(biāo)題1)build.gradle:group 'com.example'version '1.0-SNAPSHOT'allprojects { repositories { mavenCentral() }}設(shè)置.gradle:rootProject.name = 'main-project'include 'new-one'子項(xiàng)目(新項(xiàng)目):構(gòu)建 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()}使用測(cè)試運(yùn)行器運(yùn)行測(cè)試:IntelliJ idea 編譯并通過測(cè)試,但是當(dāng)我使用 gradle 時(shí),如果我運(yùn)行單個(gè)測(cè)試,它會(huì)返回: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貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
如https://github.com/junit-team/junit5-samples/blob/r5.5.2/junit5-jupiter-starter-gradle/build.gradle所示,我建議將 Jupiter 依賴項(xiàng)定義為:
testImplementation('org.junit.jupiter:junit-jupiter:5.5.2')
希望能解決這個(gè)問題。
添加回答
舉報(bào)
0/150
提交
取消