0
0
JUnittesting~20 mins

Test method naming conventions in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Identify the correct JUnit test method naming convention
Which of the following method names follows the recommended JUnit 5 test method naming conventions for clarity and readability?
ATestCalculateSum
BcalculateSumTest
CtestCalculateSum_whenInputIsValid_shouldReturnCorrectSum
Dcalculate_sum_test
Attempts:
2 left
💡 Hint
JUnit 5 encourages descriptive method names that explain the test scenario and expected behavior.
assertion
intermediate
2:00remaining
Determine the test method name from assertion purpose
You have a test that verifies the login method throws an exception when credentials are invalid. Which method name best reflects this test purpose?
AtestLogin
BloginShouldThrowExceptionForInvalidCredentials
CinvalidCredentialsTest
DcheckLoginException
Attempts:
2 left
💡 Hint
Good test method names describe the expected behavior and condition clearly.
Predict Output
advanced
2:00remaining
What is the output of the test report for this method name?
Given the following JUnit 5 test method, what will be the displayed test name in the test report by default?
JUnit
import org.junit.jupiter.api.Test;

public class CalculatorTest {
    @Test
    void addTwoNumbers_shouldReturnSum() {
        // test code
    }
}
AaddTwoNumbersShouldReturnSum()
BaddTwoNumbers should return sum
CaddTwoNumbers_shouldReturnSum()
DaddTwoNumbers-shouldReturnSum
Attempts:
2 left
💡 Hint
JUnit 5 by default shows the method name as is unless a display name is specified.
🔧 Debug
advanced
2:00remaining
Find the naming issue causing test discovery failure
A JUnit 5 test method is not being executed by the test runner. Which method name is causing this issue?
JUnit
import org.junit.jupiter.api.Test;

public class SampleTest {
    @Test
    public void TestAddition() {
        // test code
    }
}
ATestAddition
BtestAddition
CadditionTest
Dtest_addition
Attempts:
2 left
💡 Hint
JUnit 5 requires test methods to be non-static and annotated with @Test; method name casing does not prevent execution.
framework
expert
3:00remaining
Which naming style best supports behavior-driven development (BDD) in JUnit tests?
In BDD style testing with JUnit, which test method naming style is most appropriate to clearly express behavior and expected outcomes?
AvalidInputTest
BtestValidInputReturnsTrue
CcheckInput
DshouldReturnTrueWhenInputIsValid
Attempts:
2 left
💡 Hint
BDD style emphasizes expressing behavior in method names starting with 'should'.