From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Conditional test execution based on Java version and OS
From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Conditional test execution based on Java version and OS
- [Instructor] Another feature JUnit offers is conditional test execution, which allows tests to be executed selectively based on specific criteria. This allows developers to tailor their testing strategies to particular scenarios, making the testing process more efficient and targeted. Let's take a look at an example. Here we have a class that retrieves the system's information. We can use JUnit annotations to enable certain tests for certain operating systems and versions of Java. In the first test, we'll only want to enable it on Windows. We can do this with the EnabledOnOs annotation. We'll select OS.WINDOWS. This test is only valid if the operating system is Windows, so with this annotation, it'll automatically be disabled for any non-Windows OS. Then for the second test, we'll only enable it if the machine is running Linux. We'll select OS.LINUX. For the third test, we'll enable it if we're running Java 11. We'll do this with the EnabledOnJre annotation. We'll select…
Contents
-
-
-
-
-
-
Introduction to parameterized tests in JUnit2m 4s
-
(Locked)
Parameterized tests with EnumSource in JUnit 53m 21s
-
(Locked)
Parameterized tests with ValueSource in JUnit 52m 20s
-
(Locked)
Parameterized tests with CsvSource in JUnit 53m 26s
-
(Locked)
Conditional test execution based on Java version and OS2m 12s
-
(Locked)
Conditional test execution based on environment variables2m 35s
-
(Locked)
Conditional test execution based on custom conditions1m 40s
-
(Locked)
Control test execution with @Order2m 37s
-
(Locked)
Create test suites in JUnit 53m 12s
-
(Locked)
Create a test coverage report with JaCoCo4m 9s
-
(Locked)
Ensure test coverage with JaCoCo5m 41s
-
(Locked)
Execute parallel tests in JUnit 52m 41s
-
(Locked)
Custom extensions in JUnit 54m 40s
-
(Locked)
Challenge: Write a test class for a email validator1m 57s
-
(Locked)
Solution: Write a test class for a email validator5m 32s
-
-
-
-
-
-