0
0
JUnittesting~20 mins

IDE integration (IntelliJ, Eclipse) in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
IDE Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
JUnit Test Execution Result in IntelliJ
Given the following JUnit 5 test class, what will be the test execution result shown in IntelliJ's test runner after running this test?
JUnit
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class CalculatorTest {
    @Test
    void testAddition() {
        int result = 2 + 3;
        assertEquals(5, result);
    }
}
ATest fails with red cross and message 'expected 5 but was 6'.
BTest passes with green checkmark and message '1 test successful'.
CTest is skipped with yellow icon and message 'Test ignored'.
DTest does not run due to compilation error.
Attempts:
2 left
💡 Hint
Think about what the assertion is checking and the actual calculation.
assertion
intermediate
2:00remaining
Correct Assertion for Null Check in Eclipse JUnit
In Eclipse, you want to write a JUnit 5 test to verify that a method returns null. Which assertion is correct to use?
JUnit
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class UserServiceTest {
    @Test
    void testGetUserReturnsNull() {
        UserService service = new UserService();
        User user = service.getUser("unknown");
        // Which assertion to use here?
    }
}
AassertNull(user);
BassertEquals(null, user);
CassertTrue(user == null);
DassertNotNull(user);
Attempts:
2 left
💡 Hint
JUnit provides a specific assertion method for null checks.
🔧 Debug
advanced
2:00remaining
Debugging a Failing JUnit Test in IntelliJ
You run a JUnit test in IntelliJ and it fails with an AssertionError. You want to debug the test to find the problem. Which step is NOT part of the correct debugging process in IntelliJ?
AUse the 'Run' button to execute the test without breakpoints.
BInspect variable values in the debugger when execution pauses at breakpoints.
CStep through the code line by line using the debugger controls.
DSet a breakpoint inside the test method and run the test in debug mode.
Attempts:
2 left
💡 Hint
Debugging requires pausing execution to inspect state.
framework
advanced
2:00remaining
Configuring JUnit 5 in Eclipse for Maven Project
You have a Maven project in Eclipse and want to use JUnit 5 for testing. Which configuration step is essential to run JUnit 5 tests successfully in Eclipse?
ANo configuration needed; Eclipse runs JUnit 5 tests automatically.
BOnly add JUnit 4 dependency since Eclipse supports it by default.
CManually download JUnit 5 jar and add it to the build path without pom.xml changes.
DAdd the JUnit 5 dependency in the pom.xml and update the project.
Attempts:
2 left
💡 Hint
Maven manages dependencies via pom.xml.
🧠 Conceptual
expert
3:00remaining
Understanding Test Reports in IntelliJ for Parameterized Tests
You run a parameterized JUnit 5 test in IntelliJ with 3 different input sets. How does IntelliJ display the test results in the test runner panel?
JUnit
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static org.junit.jupiter.api.Assertions.*;

public class MathTest {
    @ParameterizedTest
    @ValueSource(ints = {1, 2, 3})
    void testIsPositive(int number) {
        assertTrue(number > 0);
    }
}
AShows one test failing if any input fails, no details on which.
BShows 3 separate tests with no grouping, all passing.
CShows one test with 3 sub-tests, each passing individually.
DShows no test results because parameterized tests are unsupported.
Attempts:
2 left
💡 Hint
IntelliJ groups parameterized tests under one test name with sub-tests.