0
0
JUnittesting~10 mins

IDE integration (IntelliJ, Eclipse) in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the JUnit test annotation.

JUnit
import org.junit.[1];
Drag options to blanks, or click blank then click option'
AIgnore
BBefore
CAfter
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing @Before or @After instead of @Test
Forgetting to import any annotation
2fill in blank
medium

Complete the code to create a test method named testAddition.

JUnit
@Test
public void [1]() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AtestAddition
BadditionTest
CaddTest
DcheckAddition
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that don't start with 'test'
Using invalid Java method names
3fill in blank
hard

Fix the error in the assertion to check if sum equals 5.

JUnit
int sum = 2 + 3;
assertEquals([1], sum);
Drag options to blanks, or click blank then click option'
A5
Bsum
C"5"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the actual value as expected
Using a string instead of an integer
4fill in blank
hard

Fill both blanks to import the assertion and write a failing test method.

JUnit
import static org.junit.Assert.[1];

@Test
public void testFail() {
    [2]("Failing test");
}
Drag options to blanks, or click blank then click option'
Afail
BassertTrue
DassertEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Importing assertTrue but calling fail
Calling assertEquals instead of fail
5fill in blank
hard

Fill all three blanks to write a test that checks if a list contains a value.

JUnit
import static org.junit.Assert.[1];
import java.util.List;

@Test
public void testListContains() {
    List<String> items = List.of("apple", "banana", "cherry");
    boolean contains = items.contains("banana");
    [2]("List should contain banana", contains);
    [3](true, contains);
}
Drag options to blanks, or click blank then click option'
AassertTrue
BassertFalse
DassertEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertFalse instead of assertTrue
Mixing up assertTrue and assertEquals