0
0
JUnittesting~10 mins

First JUnit test - 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.jupiter.api.[1];
Drag options to blanks, or click blank then click option'
AAfterAll
BBeforeEach
CDisabled
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing other annotations like BeforeEach instead of Test.
Forgetting to import any annotation.
2fill in blank
medium

Complete the code to write a simple test method named testAddition.

JUnit
@Test
public void [1]() {
    int sum = 2 + 3;
    org.junit.jupiter.api.Assertions.assertEquals(5, sum);
}
Drag options to blanks, or click blank then click option'
AtestAddition
BcheckSum
CadditionTest
DsumTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than requested.
Forgetting the @Test annotation.
3fill in blank
hard

Fix the error in the assertion to correctly check that result equals 10.

JUnit
int result = 5 + 5;
org.junit.jupiter.api.Assertions.assertEquals([1], result);
Drag options to blanks, or click blank then click option'
A10
B5 + 5
C"10"
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable result as expected value.
Using a string "10" instead of integer 10.
4fill in blank
hard

Fill both blanks to create a test method that checks if multiply(2, 3) returns 6.

JUnit
@Test
public void [1]() {
    int output = multiply(2, 3);
    org.junit.jupiter.api.Assertions.[2](6, output);
}
Drag options to blanks, or click blank then click option'
AtestMultiply
BassertEquals
CassertTrue
DmultiplyTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertTrue instead of assertEquals.
Using a wrong method name.
5fill in blank
hard

Fill all three blanks to write a test method that verifies isEven(4) returns true.

JUnit
@Test
public void [1]() {
    boolean result = isEven([2]);
    org.junit.jupiter.api.Assertions.[3](result);
}
Drag options to blanks, or click blank then click option'
AtestIsEven
B4
CassertEquals
DassertTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertEquals instead of assertTrue for boolean checks.
Passing wrong input value.