0
0
JUnittesting~20 mins

Gradle dependency setup in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gradle JUnit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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'
    }
}
ABuild fails due to missing JUnit engine dependency
BTests run using JUnit 4 platform, but no test events are shown in the console
CTests run using JUnit 5 platform, showing passed and failed test events in the console
DTests run but no test results are displayed because testLogging is not configured
Attempts:
2 left
💡 Hint
Check which JUnit version is configured and how testLogging is set.
assertion
intermediate
1: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?
AtestImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
Bimplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
CruntimeOnly 'org.junit.jupiter:junit-jupiter-api:5.9.2'
DcompileOnly 'org.junit.jupiter:junit-jupiter-api:5.9.2'
Attempts:
2 left
💡 Hint
JUnit API is only needed when compiling test code, not main code.
🔧 Debug
advanced
2: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()
}
AJUnit dependency version is outdated and causes build failure
BJUnit 4 dependency is used but <code>useJUnitPlatform()</code> requires JUnit 5 tests
CMissing <code>testRuntimeOnly</code> dependency for JUnit engine
DThe <code>test</code> task is missing <code>testLogging</code> configuration
Attempts:
2 left
💡 Hint
Check compatibility between JUnit version and test platform used.
framework
advanced
3: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?
A
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
test { useJUnitPlatform() }
B
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
test { useJUnitPlatform() }
C
implementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
runtimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
test { useJUnitPlatform() }
D
testImplementation 'junit:junit:4.13.2'
test { useJUnitPlatform() }
Attempts:
2 left
💡 Hint
Parameterized tests need a separate JUnit 5 params dependency.
🧠 Conceptual
expert
3: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?
ABuild fails during compilation due to missing engine classes
BTests run but no test results are reported
CTests run successfully because API includes engine classes
DTests compile but fail at runtime with ClassNotFoundException for JUnit engine classes
Attempts:
2 left
💡 Hint
Consider the role of API vs engine dependencies in JUnit 5.