Recall & Review
beginner
What is the purpose of the @EnabledIfEnvironmentVariable annotation in JUnit?
It allows a test or test class to run only if a specific environment variable matches a given value. This helps control test execution based on environment settings.Click to reveal answer
beginner
How do you specify the environment variable name and value in @EnabledIfEnvironmentVariable?
You use the 'named' attribute for the environment variable name and the 'matches' attribute for the expected value pattern. For example: @EnabledIfEnvironmentVariable(named = "ENV_VAR", matches = "true")
Click to reveal answer
beginner
Can @EnabledIfEnvironmentVariable be used on both test methods and test classes?
Yes, it can be applied to individual test methods or entire test classes to conditionally enable or disable them based on environment variables.
Click to reveal answer
beginner
What happens if the environment variable does not match the specified value in @EnabledIfEnvironmentVariable?
The test or test class is skipped and not executed. This helps avoid running tests in unsuitable environments.Click to reveal answer
intermediate
Give a real-life example where @EnabledIfEnvironmentVariable is useful.
When you have tests that should only run in a development environment, you can set an environment variable like 'ENV' to 'dev' and use @EnabledIfEnvironmentVariable(named = "ENV", matches = "dev") to run those tests only in development.
Click to reveal answer
What does @EnabledIfEnvironmentVariable do in JUnit?
✗ Incorrect
The annotation enables tests conditionally based on environment variable values.
Which attribute specifies the environment variable name in @EnabledIfEnvironmentVariable?
✗ Incorrect
The 'named' attribute is used to specify the environment variable name.
If the environment variable does not match the expected value, what happens to the test?
✗ Incorrect
Tests are skipped if the environment variable does not match.
Can @EnabledIfEnvironmentVariable be applied to a test class?
✗ Incorrect
It can be applied to both test classes and test methods.
Which of these is a valid use of @EnabledIfEnvironmentVariable?
✗ Incorrect
The correct attributes are 'named' and 'matches'.
Explain how @EnabledIfEnvironmentVariable controls test execution in JUnit.
Think about how environment settings can decide if a test runs.
You got /4 concepts.
Describe a scenario where using @EnabledIfEnvironmentVariable would be helpful.
Consider when some tests should not run everywhere.
You got /3 concepts.