Complete the code to skip the test if the assumption fails.
import static org.junit.jupiter.api.Assumptions.*; @Test void testOnlyOnWindows() { assumeTrue(System.getProperty("os.name").startsWith([1])); // test code here }
The assumption checks if the OS name starts with "Windows". If not, the test is skipped.
Complete the code to skip the test if the environment variable is not set to 'test'.
import static org.junit.jupiter.api.Assumptions.*; @Test void testOnlyInTestEnv() { assumeTrue("test".equals(System.getenv([1]))); // test code here }
The assumption checks if the environment variable 'APP_ENV' equals 'test'. If not, the test is skipped.
Fix the error in the assumption to correctly skip the test when the condition is false.
import static org.junit.jupiter.api.Assumptions.*; @Test void testSkipIfNotDebug() { assumeTrue(System.getProperty("debug") [1] "true"); // test code here }
Use .equals("true") to compare strings correctly in Java. Using '==' compares references, not content.
Fill both blanks to assume the test runs only if the Java version is 17 or higher.
import static org.junit.jupiter.api.Assumptions.*; @Test void testOnlyOnJava17OrHigher() { String version = System.getProperty("java.version"); assumeTrue(Integer.parseInt(version.split("\\.")[[1]]) [2] 17); // test code here }
The first part of the version string is at index 0. We check if it is greater than or equal to 17 to run the test.
Fill all three blanks to assume the test runs only if the system property 'env' is 'dev' and the user is 'admin'.
import static org.junit.jupiter.api.Assumptions.*; @Test void testOnlyForDevAdmin() { assumeTrue(System.getProperty([1]).equals([2]) && System.getProperty([3]).equals("admin")); // test code here }
The assumption checks if the 'env' property equals 'dev' and the 'user' property equals 'admin'. If not, the test is skipped.