0
0
JUnittesting~10 mins

CI pipeline test stage 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 define a JUnit test method.

JUnit
@Test
public void [1]() {
    assertEquals(4, 2 + 2);
}
Drag options to blanks, or click blank then click option'
Astart
Bmain
CrunTest
DtestAddition
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' as test method name
Using invalid method names
2fill in blank
medium

Complete the code to import the JUnit assertion class.

JUnit
import org.junit.[1];
Drag options to blanks, or click blank then click option'
AAssert
BTest
CAssertions
DRule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Test' instead of 'Assert'
Using 'Assertions' which is JUnit 5
3fill in blank
hard

Fix the error in the test annotation.

JUnit
public class CalculatorTest {
    [1]
    public void testSum() {
        assertEquals(5, 2 + 3);
    }
}
Drag options to blanks, or click blank then click option'
A@Test
B@test
C@TestMethod
D@Testing
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase '@test'
Using non-existent annotations like '@TestMethod'
4fill in blank
hard

Fill both blanks to create a test method that checks if a list is empty.

JUnit
@Test
public void [1]() {
    List<String> list = new ArrayList<>();
    assert[2](list.isEmpty());
}
Drag options to blanks, or click blank then click option'
AtestListEmpty
BassertTrue
CassertFalse
DcheckEmpty
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'assertFalse' which would fail the test
Using unclear method names
5fill in blank
hard

Fill all three blanks to write a test method that verifies string length.

JUnit
@Test
public void [1]() {
    String text = "hello";
    assertEquals([2], text.[3]());
}
Drag options to blanks, or click blank then click option'
AtestStringLength
B5
Clength
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size()' which is for collections
Wrong expected length value