我嘗試使用 IntelliJ在 GitHub 上運行這個開源專案的單個單元測驗。
Execution failed for task ':test'.
No tests found for given includes: [DNAnalyzer.MainTest.mainClassshouldExist](--tests filter)
測驗類
package DNAnalyzer;
import org.junit.jupiter.api.Test;
public class MainTest {
@Test
public void mainClassshouldExist() throws ClassNotFoundException {
Class.forName("DNAnalyzer.Main");
}
}
build.gradle
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.5.1/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit test framework.
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.1'
// This dependency is used by the application.
implementation "com.google.guava:guava:31.0.1-jre"
// Picocli
implementation "info.picocli:picocli:4.6.3"
}
application {
// Define the main class for the application.
mainClass = "DNAnalyzer.Main"
}
test {
useJUnitPlatform()
}
jar {
manifest {
attributes 'Main-Class': 'DNAnalyzer.Main'
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
我試過的
更新到最新的 JUnit
testImplementation 組:'org.junit.jupiter',名稱:'junit-jupiter-api',版本:'5.9.1'
將此添加到我的 build.gradle 檔案中:
測驗 { useJUnitPlatform() }
目前唯一的解決方法:
當我轉到 Settings -> Build-Tool -> Gradle 并將測驗執行設定為“Run tests wit: IntelliJ IDEA”時,測驗會正確執行。
謝謝
uj5u.com熱心網友回復:
問題來自包含您的測驗類的包的命名DNAnalyzer,它并沒有真正遵循 java 命名約定,因為它以/包含大寫字母開頭。
在執行單個測驗用例或測驗類時,IntelliJ 將通過呼叫test具有特定過濾器的任務來委托給 Gradle,如下所示
./gradlew :test --tests "DNAnalyzer.MainTest.mainClassshouldExist"
在 Gradle 中存在這個問題:https ://github.com/gradle/gradle/issues/20350 :“test --tests 不適用于包含大寫字母的包”。
嘗試將您的測驗類移動到另一個命名良好的包中,您將不會遇到此問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/523314.html
標籤:爪哇毕业典礼朱尼特
