Challenge - 5 Problems
JUnit Test Result Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
JUnit test result for a passing test
What is the test execution result shown in the JUnit XML report for this passing test?
JUnit
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class SampleTest { @Test void testAlwaysPasses() { assertTrue(5 > 1); } }
Attempts:
2 left
💡 Hint
Passing tests do not have failure, error, or skipped tags in the JUnit XML report.
✗ Incorrect
In JUnit XML reports, a passing test is represented by a element without child elements like , , or . Option B correctly shows this.
❓ Predict Output
intermediate2:00remaining
JUnit test result for a failed assertion
What is the test execution result shown in the JUnit XML report for this failing test?
JUnit
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class SampleTest { @Test void testFails() { assertEquals(5, 3); } }
Attempts:
2 left
💡 Hint
Failed assertions are reported with a tag including the failure message.
✗ Incorrect
JUnit reports failed assertions inside the tag with a message describing the assertion error. Option A correctly shows this.
❓ assertion
advanced2:00remaining
Correct assertion to verify test failure message in JUnit
Which assertion correctly verifies that a JUnit test failure message contains the text "expected:<5> but was:<3>"?
Attempts:
2 left
💡 Hint
Use assertTrue to check if the failure message contains the expected substring.
✗ Incorrect
The failure message may contain additional text, so checking if it contains the substring is correct. Option A uses assertTrue with contains(), which is appropriate.
🔧 Debug
advanced2:00remaining
Identify the cause of missing test results in JUnit report
A JUnit XML report is missing test results for some tests. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
JUnit requires test classes to be public to discover and run tests.
✗ Incorrect
JUnit only runs tests in public classes. If the test class is not public, tests are not executed and results are missing. Other options do not prevent test execution or reporting.
❓ framework
expert2:00remaining
Best practice for publishing JUnit test results in CI pipeline
In a CI pipeline, which approach ensures reliable publishing of JUnit test results for all test runs, including flaky tests and retries?
Attempts:
2 left
💡 Hint
CI tools often support merging multiple JUnit XML files to aggregate results.
✗ Incorrect
Merging all JUnit XML files from all runs and retries ensures complete and accurate test reporting. Ignoring retries or manual editing risks losing data or errors.