Recall & Review
beginner
What is the purpose of the @EnabledIf annotation in JUnit?
The @EnabledIf annotation allows tests to run only when a custom condition is true. It helps control test execution based on dynamic logic.
Click to reveal answer
beginner
How do you write a simple custom condition method for @EnabledIf?
Create a static method that returns a boolean. The method contains the logic to decide if the test should run. Example: <br>
public static boolean isTestEnabled() { return true; }Click to reveal answer
intermediate
What must be true about the method used in @EnabledIf's expression?
The method must be static, return a boolean, and be accessible from the test class or a referenced class.Click to reveal answer
intermediate
How does @EnabledIf improve test suite efficiency?
It skips tests that don't meet certain conditions, saving time and resources by not running irrelevant tests.
Click to reveal answer
beginner
Give an example of using @EnabledIf with a custom condition method.
Example:<br>
@EnabledIf(expression = "com.example.MyConditions.isFeatureEnabled()", reason = "Feature must be enabled")
void testFeature() { /* test code */ }Click to reveal answer
What type of method can be used with @EnabledIf to control test execution?
✗ Incorrect
The method must be static and return a boolean to be used with @EnabledIf.
What happens if the @EnabledIf condition returns false?
✗ Incorrect
If the condition is false, JUnit skips the test.
Where can the method used in @EnabledIf be located?
✗ Incorrect
The method can be in the test class or any class accessible to the test.
Which of these is a valid reason to use @EnabledIf?
✗ Incorrect
@EnabledIf is used to conditionally run tests, such as when a feature flag is enabled.
What is the return type required for a method used in @EnabledIf expression?
✗ Incorrect
The method must return a boolean to indicate if the test should run.
Explain how to create and use a custom condition with @EnabledIf in JUnit.
Think about a method that returns true or false and how you tell JUnit to use it.
You got /4 concepts.
Describe benefits of using @EnabledIf for conditional test execution.
Consider why you might want to run some tests only sometimes.
You got /4 concepts.