0
0
JUnittesting~20 mins

Test result publishing in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit Test Result Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
A<testcase classname="SampleTest" name="testAlwaysPasses" time="0.001"><error message="Exception thrown"/></testcase>
B<testcase classname="SampleTest" name="testAlwaysPasses" time="0.001"/>
C<testcase classname="SampleTest" name="testAlwaysPasses" time="0.001"><skipped/></testcase>
D<testcase classname="SampleTest" name="testAlwaysPasses" time="0.001"><failure message="Assertion failed"/></testcase>
Attempts:
2 left
💡 Hint
Passing tests do not have failure, error, or skipped tags in the JUnit XML report.
Predict Output
intermediate
2: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);
    }
}
A<testcase classname="SampleTest" name="testFails" time="0.001"><failure message="expected:&lt;5&gt; but was:&lt;3&gt;"/></testcase>
B<testcase classname="SampleTest" name="testFails" time="0.001"/>
C<testcase classname="SampleTest" name="testFails" time="0.001"><error message="NullPointerException"/></testcase>
D<testcase classname="SampleTest" name="testFails" time="0.001"><skipped/></testcase>
Attempts:
2 left
💡 Hint
Failed assertions are reported with a tag including the failure message.
assertion
advanced
2: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>"?
AassertTrue(failureMessage.contains("expected:<5> but was:<3>"));
BassertEquals("expected:<5> but was:<3>", failureMessage);
CassertNull(failureMessage);
DassertFalse(failureMessage.contains("expected:<5> but was:<3>"));
Attempts:
2 left
💡 Hint
Use assertTrue to check if the failure message contains the expected substring.
🔧 Debug
advanced
2: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?
ATest methods throw checked exceptions.
BTests use assertTrue assertions instead of assertEquals.
CTest methods have void return type.
DTests are annotated with @Test but the test class is not public.
Attempts:
2 left
💡 Hint
JUnit requires test classes to be public to discover and run tests.
framework
expert
2: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?
AManually edit the JUnit XML files to remove duplicate test cases before publishing.
BOnly publish the JUnit XML file from the first test run, ignoring retries.
CConfigure the CI to collect and merge all JUnit XML files generated by each test run and retry.
DPublish test results only if the test run passes without retries.
Attempts:
2 left
💡 Hint
CI tools often support merging multiple JUnit XML files to aggregate results.