Challenge - 5 Problems
Gradle Test Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Gradle test task with failing test
Given the following JUnit test class, what will be the output status of the Gradle
test task when executed?JUnit
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class SampleTest { @Test void testSuccess() { assertEquals(2, 1 + 1); } @Test void testFailure() { assertTrue(false); } }
Attempts:
2 left
💡 Hint
Remember that a failing assertion causes the test to fail and the Gradle test task to fail.
✗ Incorrect
The test class has one test that always fails (assertTrue(false)). Gradle test task runs all tests and fails if any test fails.
❓ assertion
intermediate1:30remaining
Correct assertion to verify test task execution
Which JUnit assertion correctly verifies that the Gradle test task executed exactly 5 tests successfully?
Attempts:
2 left
💡 Hint
You want to check the total number of tests run, not failures or null values.
✗ Incorrect
The method getTestCount() returns the total tests run. To verify 5 tests ran successfully, assertEquals(5, result.getTestCount()) is correct.
🔧 Debug
advanced2:00remaining
Debugging Gradle test task skipping tests
You run
gradle test but no tests are executed. Which of the following is the most likely cause?Attempts:
2 left
💡 Hint
Gradle looks for test classes matching specific name patterns by default.
✗ Incorrect
Gradle runs tests matching patterns like *Test.java by default. If test classes don't match, no tests run.
❓ framework
advanced1:30remaining
Configuring Gradle test task for JUnit 5
Which Gradle configuration snippet correctly enables JUnit 5 platform for the
test task?Attempts:
2 left
💡 Hint
JUnit 5 requires a specific platform configuration in Gradle.
✗ Incorrect
JUnit 5 tests require
useJUnitPlatform() in the Gradle test task to run properly.🧠 Conceptual
expert2:30remaining
Impact of test task parallel execution on test results
If you configure the Gradle
test task to run tests in parallel, which of the following is a potential risk?Attempts:
2 left
💡 Hint
Think about what happens when tests run at the same time and share data.
✗ Incorrect
Parallel test execution can cause issues if tests share mutable static data, leading to flaky tests.