0
0
JUnittesting~10 mins

Test classes and naming 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 declare a JUnit test class named correctly.

JUnit
public class [1] {

}
Drag options to blanks, or click blank then click option'
ACalculatorTest
Bcalculator
CTestCalculator
DcalcTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incomplete names like 'calculator' or 'calcTest'.
Starting the name with 'Test' instead of ending with it.
2fill in blank
medium

Complete the code to import the JUnit 5 test annotation.

JUnit
import org.junit.jupiter.api.[1];
Drag options to blanks, or click blank then click option'
ATest
BBeforeEach
CTestClass
DTestSuite
Attempts:
3 left
💡 Hint
Common Mistakes
Importing annotations like 'BeforeEach' when the task asks for the test annotation.
Using 'TestClass' or 'TestSuite' which are not JUnit 5 annotations.
3fill in blank
hard

Fix the error in the test class declaration by completing the class name correctly.

JUnit
public class [1] {

    @Test
    void exampleTest() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
ATestExample
BExample
CExampleTest
Dexampletest
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class names which is against Java naming conventions.
Starting the name with 'Test' instead of ending with it.
4fill in blank
hard

Fill both blanks to complete a JUnit 5 test class with a test method named correctly.

JUnit
public class [1] {

    @[2]
    void shouldAddNumbers() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
ACalculatorTest
BTest
CBeforeEach
DAdderTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@BeforeEach' instead of '@Test' for the test method.
Naming the class without the 'Test' suffix.
5fill in blank
hard

Fill all three blanks to complete a JUnit 5 test class with a test method and proper import.

JUnit
import org.junit.jupiter.api.[1];

public class [2] {

    @[3]
    void testMultiply() {
        // test code
    }
}
Drag options to blanks, or click blank then click option'
ATest
BMultiplierTest
DMultiplyTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using different annotations for import and method.
Class name not ending with 'Test'.