Challenge - 5 Problems
JUnit Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
JUnit 5 renamed lifecycle annotations to be more descriptive per test method or all tests.
✗ Incorrect
JUnit 4 uses @Before to run setup before each test method. JUnit 5 replaces this with @BeforeEach to clarify it runs before each test.
❓ Predict Output
intermediate1: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); } }
Attempts:
2 left
💡 Hint
JUnit 5 does not require @RunWith for basic tests.
✗ Incorrect
The test method asserts 2 + 3 equals 5, which is true, so the test passes.
❓ assertion
advanced2: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();
}Attempts:
2 left
💡 Hint
JUnit 5 uses assertThrows for exception testing.
✗ Incorrect
JUnit 5 uses assertThrows to check exceptions. Option D is JUnit 4 style and won't compile in JUnit 5 without vintage engine.
❓ framework
advanced2:00remaining
JUnit 5 Modular Architecture
Which statement best describes JUnit 5's architecture compared to JUnit 4?
Attempts:
2 left
💡 Hint
JUnit 5 separates concerns into modules for flexibility.
✗ Incorrect
JUnit 5 consists of the Jupiter module for new tests, Vintage for backward compatibility, and Platform for launching tests.
🔧 Debug
expert2: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"); } }
Attempts:
2 left
💡 Hint
JUnit 5 identifies tests by annotations, not method names.
✗ Incorrect
JUnit 5 runs methods annotated with @Test. Without it, the method is ignored.