Recall & Review
beginner
Why are test naming conventions important in JUnit?
They help make tests easy to understand, maintain, and identify what behavior is being tested. Good names improve communication among team members and speed up debugging.
Click to reveal answer
beginner
What is a common pattern for naming JUnit test methods?
Use the format: <methodName>_<condition>_<expectedResult>. For example, calculateSum_zeroInput_returnsZero() clearly shows what is tested and expected.
Click to reveal answer
beginner
What is the benefit of using descriptive test names over generic ones like
test1()?Descriptive names explain the test purpose without reading the code. Generic names force you to open the test to understand it, wasting time and causing confusion.
Click to reveal answer
intermediate
How can you handle long test names in JUnit while keeping readability?
Use underscores or camelCase to separate parts. Keep names focused on one behavior. If too long, consider splitting the test into smaller tests.
Click to reveal answer
intermediate
What role do annotations like @DisplayName play in test naming?
They allow adding human-friendly names to tests that appear in reports and IDEs, improving readability without changing method names.
Click to reveal answer
Which of these is a good JUnit test method name?
✗ Incorrect
Option D clearly describes the method under test, the condition, and the expected result.
What is the main purpose of using @DisplayName in JUnit tests?
✗ Incorrect
@DisplayName provides a human-friendly name for better readability in reports and IDEs.
Which naming style is recommended for JUnit test methods?
✗ Incorrect
Using methodName_condition_expectedResult clearly communicates what the test does.
Why avoid generic test names like test1()?
✗ Incorrect
Generic names do not explain what is tested, making maintenance and debugging harder.
If a test name becomes too long, what should you do?
✗ Incorrect
Splitting tests keeps names clear and focused, improving readability and maintainability.
Explain why descriptive test names are important in JUnit and how they improve testing.
Think about how you find a problem quickly when you know what each test does.
You got /4 concepts.
Describe a good pattern for naming JUnit test methods and why it helps.
Imagine telling a friend exactly what the test checks without showing the code.
You got /4 concepts.