0
0
JUnittesting~20 mins

JUnit 4 vs JUnit 5 (Jupiter) differences - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
JUnit 4 vs JUnit 5: Annotation Differences
Which annotation is used in JUnit 5 to replace JUnit 4's @Before annotation for setup methods?
A@Init
B@BeforeAll
C@BeforeEach
D@Setup
Attempts:
2 left
💡 Hint
JUnit 5 renamed lifecycle annotations to be more descriptive per test method or all tests.
Predict Output
intermediate
1:30remaining
JUnit 5 Test Execution Result
What will be the test execution result of this JUnit 5 test class?
JUnit
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class SampleTest {
    @Test
    void testSum() {
        assertEquals(5, 2 + 3);
    }
}
ATest fails with AssertionError
BTest passes
CCompilation error due to missing @RunWith
DTest ignored
Attempts:
2 left
💡 Hint
JUnit 5 does not require @RunWith for basic tests.
assertion
advanced
2:00remaining
Correct Assertion for Exception Testing in JUnit 5
Which assertion correctly tests that a method throws NullPointerException in JUnit 5?
JUnit
public void methodThatThrows() {
    throw new NullPointerException();
}
AassertException(NullPointerException.class, () -> methodThatThrows());
B@Test(expected = NullPointerException.class) public void test() { methodThatThrows(); }
CassertThatThrownBy(() -> methodThatThrows()).isInstanceOf(NullPointerException.class);
DassertThrows(NullPointerException.class, () -> methodThatThrows());
Attempts:
2 left
💡 Hint
JUnit 5 uses assertThrows for exception testing.
framework
advanced
2:00remaining
JUnit 5 Modular Architecture
Which statement best describes JUnit 5's architecture compared to JUnit 4?
AJUnit 5 is composed of three modules: Jupiter, Vintage, and Platform.
BJUnit 5 uses the same runner mechanism as JUnit 4.
CJUnit 5 requires no dependencies and runs standalone.
DJUnit 5 is a single monolithic jar replacing JUnit 4.
Attempts:
2 left
💡 Hint
JUnit 5 separates concerns into modules for flexibility.
🔧 Debug
expert
2:30remaining
JUnit 5 Test Not Executing
Given this JUnit 5 test class, why does the test method not run?
JUnit
import org.junit.jupiter.api.Test;

public class MyTest {
    public void testMethod() {
        System.out.println("Running test");
    }
}
AThe test method is missing the @Test annotation.
BThe test method must be static.
CThe class must extend a JUnit 5 base test class.
DJUnit 5 requires test methods to be public static void.
Attempts:
2 left
💡 Hint
JUnit 5 identifies tests by annotations, not method names.