There is a nice possibility to run JUnit test with parameters where the same test method is executed multiple times with different data as described here: http://junit.org/apidocs/org/junit/runners/Parameterized.html
Unfortunately, it only seems possible to use primitive parameters or Strings, but not objects. Is there any workaround known for this?
The type of the data()
method in the use of the @Parameters annotation is List<Object[]>
, so you can put in any object.
To pass in, e.g., a Money
object, your array to be converted to a list would be:
{ { new Money(26, "CHF") }, { new Money(12, "USD") } }
The constructor of the test class should take a Money object as argument then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With