Junit 5's Parameterized Tests - making one test run many test cases

Опубликовано: 30 Май 2026
на канале: Merlin Wellington
617
9

JUnit's parameterized tests allow us to specify a lot of test cases for one test method. They help us eliminate copy-and-paste code in our tests and give us better feedback when something fails. Setting up your project to do this requires a couple of maven dependencies. Once that's set up, the trick is figuring out how to feed the data to your tests. I cover most of the test case sources. Combining parameterized tests with other JUnit features (like @BeforeEach and @BeforeAll) and with mock objects can make them much more powerful.


In this video I'll walk you through:
What a parameterized test is
What you need to include in your project to use parameterized tests
Using ValueSource, CSVSource, CSVFileSource, FieldSource, and MethodSource
How parameterized tests fit into the JUnit lifecycle

TIMESTAMPS
0:00 Introduction
0:24 @ValueSource and Setting Up Your Project
2:54 Why Parameterized Tests are better when things fail
3:40 @NullSource and @EmptySource
4:48 @CSVSource
5:42 @CSVFileSource
6:09 @FieldSource
7:01 @MethodSource
9:19 Conclusion

ABOUT MY CHANNEL
My channel is about good software engineering practices. We cover introductions to programming in C and Java. But I also have lots of software and computer engineering topics like PIC programming, advanced programming techniques, and things that distinguish good code from code that works.

Check out my channel here:
   / @wizardcraftcode  

Don’t forget to subscribe!

CHECK OUT MY OTHER VIDEOS:

C Programming Playlist:    • Coding in C  
Intro to Java Playlist:    • Introduction to Java Programming based on ...  
Software Engineering Topics Playlist:    • General Software Engineering Topics