0
0
JUnittesting~10 mins

Test method naming conventions 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 name the test method following JUnit conventions.

JUnit
public class CalculatorTest {
    @Test
    public void [1]() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
AtestAddition
BAdditionTest
CaddTestMethod
DcalculateAdd
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not start with 'test' or are unclear about the tested feature.
2fill in blank
medium

Complete the test method name to describe the expected behavior.

JUnit
public class UserServiceTest {
    @Test
    public void [1]() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
AtestUserCreationFailsWhenNameIsNull
BuserCreationTest
CcreateUserTestMethod
DtestCreateUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using vague or generic test method names that do not describe the test purpose.
3fill in blank
hard

Fix the error in the test method name to follow JUnit naming conventions.

JUnit
public class OrderServiceTest {
    @Test
    public void [1]() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
AprocessOrderTestMethod
BtestProcessOrderSuccessfully
CorderProcess
DProcessOrderTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using names that look like class names or omit the 'test' prefix.
4fill in blank
hard

Fill both blanks to complete a descriptive test method name and annotation.

JUnit
public class PaymentTest {
    [1]
    public void [2]() {
        // test code here
    }
}
Drag options to blanks, or click blank then click option'
A@Test
BtestPaymentFailsWithInsufficientFunds
C@Before
DpaymentTest
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the @Test annotation or using unclear method names.
5fill in blank
hard

Fill all three blanks to write a proper JUnit test method with annotation and descriptive name.

JUnit
public class LoginTest {
    [1]
    public void [2]() {
        // Arrange
        User user = new User("admin", "password");
        // Act
        boolean result = authService.login(user); 
        // Assert
        assertTrue([3]);
    }
}
Drag options to blanks, or click blank then click option'
A@Test
BtestLoginSucceedsWithValidCredentials
Cresult
DassertFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Missing @Test annotation, unclear method names, or wrong assertion methods.