Recall & Review
beginner
What is a custom annotation in Java testing?
A custom annotation is a user-defined marker or metadata that you create to add extra information to your test code, which can be processed at runtime or compile time to influence test behavior.
Click to reveal answer
beginner
How do you define a custom annotation in Java?
You define a custom annotation using the @interface keyword, specify retention policy (like RUNTIME), and optionally target elements (like METHOD or FIELD).
Click to reveal answer
intermediate
Why use custom annotations in Selenium tests?
Custom annotations help organize tests, add metadata like test priority or author, and enable reusable logic such as custom waits or setup steps, making tests cleaner and easier to maintain.
Click to reveal answer
intermediate
What is the RetentionPolicy.RUNTIME in custom annotations?
RetentionPolicy.RUNTIME means the annotation is available during runtime via reflection, allowing test frameworks to read and act on the annotation while tests run.
Click to reveal answer
beginner
Give an example of a simple custom annotation for marking tests as 'Critical'.
Example:
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface CriticalTest {
String value() default "";
}
This annotation can be placed on test methods to mark them as critical.Click to reveal answer
Which keyword is used to create a custom annotation in Java?
✗ Incorrect
The @interface keyword is used to define a custom annotation in Java.
What does RetentionPolicy.RUNTIME mean for a custom annotation?
✗ Incorrect
RetentionPolicy.RUNTIME means the annotation is kept in the compiled class and can be accessed during runtime.
Why might you use custom annotations in Selenium tests?
✗ Incorrect
Custom annotations add metadata like priority or author and help control test execution flow.
Which Java package is commonly used to access annotations at runtime?
✗ Incorrect
The java.lang.reflect package provides classes to inspect annotations at runtime.
What element type would you specify to apply a custom annotation only to methods?
✗ Incorrect
ElementType.METHOD restricts the annotation usage to methods only.
Explain how to create and use a custom annotation in Selenium Java tests.
Think about how annotations add metadata and how Selenium tests can read them.
You got /5 concepts.
Describe the benefits of using custom annotations in test automation.
Consider how annotations help manage many tests in a project.
You got /5 concepts.