Java Test Runner not recording any test output
When I first try to execute all JUnit tests, I receive this on the Debug Console:
After cleaning the Gradle project with "./gradlew clean build --refresh-dependencies" and trying to run the tests again, it tells me that my build has failed.
Here is my current build.gradle.kts file:
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id("java")
application
id("org.openjfx.javafxplugin") version "0.1.0"
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
// https://mvnrepository.com/artifact/org.mockito/mockito-core
testImplementation("org.mockito:mockito-junit-jupiter:5.15.+")
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
sourceSets {
named("main") {
java {
setSrcDirs(listOf("src/main/java"))
}
}
}
}
javafx {
version = "21.0.6"
modules("javafx.controls", "javafx.fxml")
}
application {
// Define the main class for the application.
mainClass = "main"
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
I tried reloading my project, cleaning java language workspace etc. nothing seemed to change anything. Important to note is that on a completely different cloned repository with the same gradle configurations, everything works fine.
Would appreciate any help with this, otherwise I'll stick to IntelliJ with the testing.
Hi @G3ntiLP, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Suggestions to resolve test discovery and execution failures:
- Update your Java Test Runner extension to the latest version and reload VS Code.
- Clean the Java language server workspace (F1 → “Java: Clean the Java language server workspace”) and restart.
- Explicitly add the JUnit engine to your Gradle build:
dependencies { // … testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") } - From VS Code’s Gradle Tasks view, run the
testtask to confirm Gradle can discover and execute tests outside the Test Runner UI. - Check for conflicting JUnit Platform versions on the classpath (e.g., transitive dependencies pulling an older
junit-platform-commons).
Other references with high confidence worth checking:
-
Test Explorer not displaying any java tests, but tests run successfully
Description: Tests run via commands but aren’t shown in Test Explorer. Similar discovery failures without clear errors.
Other references with low confidence
No additional relevant issues found.
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!