Parameterized tests were added to JUnit 4 so developers can run tests over many times with different values. To create a parameterized test: Annotate test class. Create a public static method, annotated, that returns a Collection of Objects (as Array) as test data set. Create a public constructor that takes in what is equivalent to one row of test data. Create an instance variable for each column of test data. Create your test case(s) using the instance variables as the source of the test data.
- View Offline
- [Announcer] With JUnit 4 they added another feature…that allows you run paramaterized tests.…This feature allows the developer to run tests,…including multiple values at one time.…JUnit allows you to use parameters in the test class.…The class can contain one test method,…and the method is executed with…the list of parameters provided.…There are five steps that you need to follow…to create a paramaterized test,…and I'm going to show you with an example.…
The first one is to annotate the test class…with @sign run with.…As you can see here on line 21,…in parenthesis you can either list parameterized dot class,…or value equals parameterized dot class,…they do the same thing.…Let me scroll down a little bit.…On line 22 is the name of my class,…and I have three private int variables.…Num A, Num B, and expected.…In this particular program I'm going to take Num A,…and I'm going to add it to Num B,…and that's going to be the value…that I expect to get return from a call…to my Matthew Tills dot Java.…
Let me switch over there real quick so you can see.…
- What is JUnit?
- Comparing values with assertions
- Using JUnit with different Java IDEs
- Creating basic unit tests
- Testing for exception handling
- Creating parameterized tests