From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Parameterized tests with ValueSource in JUnit 5
From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Parameterized tests with ValueSource in JUnit 5
- [Instructor] Let's refactor a non-enum test class to use parameterized tests. Here, we have a class with several tests that verify the functionality of an isPalindrome method. We can simplify this using the parameterized test and value source annotations. We'll separate those that are palindromes and those that are not palindromes into separate tests. Then we'll use the ValueSource annotation to test specific cases. For is palindrome, we'll pass in the empty string, a racecar, RaceCar with capitalization, and then those that are not palindromes would be hello, world, java, and JUnit. Let's delete these other tests and run it. And the tests pass. In our test results, we can see each test run, and run a specific case again, if we want to. For example, we could run just a again with the play button, and only that case will be run. With parametrized tests, we can consolidate similar test cases into single parametrized test methods.
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
-
-
-
-
-
-