0
0
JUnittesting~5 mins

@DisplayName for readable names in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @DisplayName annotation in JUnit?
The @DisplayName annotation is used to give a test method or class a readable and descriptive name that appears in test reports and IDEs, making tests easier to understand.
Click to reveal answer
beginner
How do you use @DisplayName in a JUnit test method?
You place @DisplayName("Your readable name") above the test method to set a custom name that will show in test results instead of the method name.
Click to reveal answer
intermediate
Can @DisplayName be used on test classes as well as test methods?
Yes, @DisplayName can be applied to both test classes and test methods to provide readable names at both levels.
Click to reveal answer
beginner
What happens if you do not use @DisplayName in your tests?
If @DisplayName is not used, the test runner shows the method or class names as they are written in code, which may be less readable or descriptive.
Click to reveal answer
beginner
Give an example of a @DisplayName annotation for a test method.
Example: @DisplayName("Check if user login succeeds with valid credentials") void testUserLogin() { ... }
Click to reveal answer
What does the @DisplayName annotation do in JUnit?
ASets a readable name for tests in reports and IDEs
BMarks a test as disabled
CSpecifies the order of test execution
DDefines a test timeout
Where can you apply the @DisplayName annotation?
AOn both test classes and test methods
BOnly on test classes
COnly on test methods
DOnly on setup methods
If you omit @DisplayName, what name appears in test reports?
ANo name is shown
BThe method or class name as written in code
CThe package name
DA random generated name
Which of these is a valid use of @DisplayName?
A@DisplayName(123)
B@DisplayName(true)
C@DisplayName
D@DisplayName("Test user registration")
Why is using @DisplayName helpful?
AIt automatically fixes test failures
BIt speeds up test execution
CIt makes test reports easier to read and understand
DIt encrypts test data
Explain how @DisplayName improves test readability and where you can apply it.
Think about how test names appear when running tests.
You got /3 concepts.
    Describe what happens if you do not use @DisplayName in your JUnit tests.
    Consider default naming behavior in test reports.
    You got /3 concepts.