我有一個帶有 4 個測試和以下 build.gradle 的 Spring Gradle 項目:plugins { id 'org.springframework.boot' version '2.1.6.RELEASE' id 'java'}apply plugin: 'io.spring.dependency-management'version = '0.0.1'sourceCompatibility = '11'configurations { compileOnly { extendsFrom annotationProcessor }}repositories { mavenCentral()}dependencies { implementation 'org.springframework.boot:spring-boot-starter' //Rest Controller compile 'org.springframework.boot:spring-boot-starter-web' //Lombok compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' //Tests testImplementation 'org.springframework.boot:spring-boot-starter-test' testCompile 'com.h2database:h2' //Database compile("mysql:mysql-connector-java") compile("org.springframework.boot:spring-boot-starter-data-jpa") //Authentication compile 'org.springframework.security:spring-security-crypto' //e.g. PasswordEncoder compile 'org.springframework.boot:spring-boot-starter-security' //e.g. @PreAuthorize //ResourceAssembler compile 'org.springframework.boot:spring-boot-starter-hateoas' //JWT Token generation compile("com.auth0:java-jwt:3.4.0")}我可以用“運行測試”開始每個測試,它工作得很好,但是當我嘗試“運行所有測試”時,它失敗并顯示消息“運行“全部”時出錯:沒有 junit.jar”我已經嘗試添加以下任何依賴項,但都沒有解決問題:testCompile 'junit:junit:4.12testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')我正在使用 IntelliJ
1 回答

冉冉說
TA貢獻1877條經驗 獲得超1個贊
類路徑派生自包含測試的模塊的依賴項。這些文件是從工作目錄加載的,因此應該在測試的運行/調試配置中指定它。以下鏈接解釋了如何為您的測試配置它。 在 IntelliJ 中運行 JUnit 測試
另外,我想檢查 IntelliJ IDE 中的測試運行器配置。打開首選項或設置對話框窗口。檢查 Gradle 配置并查找構建、執行、部署 | 構建工具 | 搖籃 | 亞軍:
在這里,選擇 Gradle 測試運行器。配置完成后,您可以使用覆蓋率運行您的代碼,看看它是否有幫助。
添加回答
舉報
0/150
提交
取消