Challenge - 5 Problems
Gradle JUnit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Gradle test task configuration?
Given the following Gradle build snippet, what will be the result when running
./gradlew test?JUnit
plugins {
id 'java'
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
}
test {
useJUnitPlatform()
testLogging {
events 'passed', 'failed'
}
}Attempts:
2 left
💡 Hint
Check which JUnit version is configured and how testLogging is set.
✗ Incorrect
The configuration uses JUnit Jupiter API and engine dependencies for JUnit 5. The
useJUnitPlatform() enables JUnit 5 test discovery. The testLogging block configures the console to show passed and failed test events.❓ assertion
intermediate1:30remaining
Which Gradle dependency scope is correct for JUnit 5 API?
You want to write tests using JUnit 5 API in Gradle. Which dependency configuration should you use?
Attempts:
2 left
💡 Hint
JUnit API is only needed when compiling test code, not main code.
✗ Incorrect
The
testImplementation scope is used for dependencies required to compile and run test source code. JUnit API is needed only for test compilation and execution, so testImplementation is correct.🔧 Debug
advanced2:30remaining
Why does the Gradle test task not run any tests?
Given this Gradle snippet, tests are not detected or run. What is the cause?
JUnit
plugins {
id 'java'
}
dependencies {
testImplementation 'junit:junit:4.13.2'
}
test {
useJUnitPlatform()
}Attempts:
2 left
💡 Hint
Check compatibility between JUnit version and test platform used.
✗ Incorrect
The
useJUnitPlatform() enables JUnit 5 test discovery. Using JUnit 4 dependency alone means no JUnit 5 tests are found, so no tests run.❓ framework
advanced3:00remaining
How to configure Gradle to run JUnit 5 tests with parameterized support?
You want to run JUnit 5 tests including parameterized tests. Which dependencies and configuration are correct?
Attempts:
2 left
💡 Hint
Parameterized tests need a separate JUnit 5 params dependency.
✗ Incorrect
JUnit 5 parameterized tests require the
junit-jupiter-params dependency. The API and engine dependencies are also needed. The useJUnitPlatform() enables JUnit 5 test discovery.🧠 Conceptual
expert3:00remaining
What is the effect of missing
testRuntimeOnly dependency for JUnit engine in Gradle?If you declare only
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' but omit testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2', what happens when running tests?Attempts:
2 left
💡 Hint
Consider the role of API vs engine dependencies in JUnit 5.
✗ Incorrect
The API dependency provides test annotations and interfaces for compilation. The engine dependency is required at runtime to execute tests. Omitting the engine causes runtime failures.