0
0
JUnittesting~20 mins

Gradle test task in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gradle Test Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
AThe Gradle test task will fail and report 1 failed test.
BThe Gradle test task will pass with all tests successful.
CThe Gradle test task will fail with a compilation error.
DThe Gradle test task will be skipped due to no tests found.
Attempts:
2 left
💡 Hint
Remember that a failing assertion causes the test to fail and the Gradle test task to fail.
assertion
intermediate
1:30remaining
Correct assertion to verify test task execution
Which JUnit assertion correctly verifies that the Gradle test task executed exactly 5 tests successfully?
AassertFalse(result.wasSuccessful());
BassertNull(result.getTestCount());
CassertTrue(result.getFailedTests() == 5);
DassertEquals(5, result.getTestCount());
Attempts:
2 left
💡 Hint
You want to check the total number of tests run, not failures or null values.
🔧 Debug
advanced
2: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?
AThe <code>build.gradle</code> file is missing the <code>apply plugin: 'java'</code> line.
BTest classes are not named according to Gradle's default pattern (e.g., *Test.java).
CJUnit dependency is declared with <code>testImplementation</code> instead of <code>implementation</code>.
DThe <code>src/main/java</code> directory contains the test classes.
Attempts:
2 left
💡 Hint
Gradle looks for test classes matching specific name patterns by default.
framework
advanced
1:30remaining
Configuring Gradle test task for JUnit 5
Which Gradle configuration snippet correctly enables JUnit 5 platform for the test task?
A
test {
    useTestNG()
}
B
test {
    useJUnit()
}
C
test {
    useJUnitPlatform()
}
D
test {
    useJUnit4()
}
Attempts:
2 left
💡 Hint
JUnit 5 requires a specific platform configuration in Gradle.
🧠 Conceptual
expert
2: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?
ATests that share mutable static state may produce flaky or inconsistent results.
BTests will always run faster without any side effects.
CGradle will ignore test failures and mark the build as successful.
DJUnit will automatically serialize all tests to avoid conflicts.
Attempts:
2 left
💡 Hint
Think about what happens when tests run at the same time and share data.