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 isList<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:The constructor of the test class should take a Money object as argument then.
recently i started zohhak project. it lets you write:
Using object is also possible using Junit
@Parameters
.Example:-
}
Use JUnitParams instead... junitparams.googlecode.com