How to write a Data Driven Test in JUnit 4 - Parameterized Unit Test

preview_player
Показать описание
This video demonstrates converting a JUnit test into a Parameterized data driven test.

In JUnit 4 to create a parameterized test we:

- create a static method to provide the data
- the method providing data should return a collection of object arrays
- we can provide a name attribute for the parameter method which dynamically changes the display name of the test
- our test class needs a constructor to setup the data when called by JUnit Runner
- our test methods do not take parameters but they all use the same data provided by the constructor

An explanatory blog post with links to the source code is here:

---

Remember to subscribe to this YouTube channel.

Learn more about my books and online training at:

Follow me on:

Рекомендации по теме
Комментарии
Автор

Excelent explanation. I wasn't understanding the concept really well, but I was able to get the code from class and relate with your material. Thank you very much!

raulsouto
Автор

That’s a nice video, thank you a lot!

nickfast
Автор

Greate explanation, thank you very much!!

hm
Автор

How do we deal with throwing exceptions in this? Say, for example, the expected behavior for the code I am testing is to throw a NullPointerException. How do I add that to my list of test values?

stephenjohnson
welcome to shbcf.ru