Saturday, 15 May 2010

java - JUnit parameterized test with varying parameters -



java - JUnit parameterized test with varying parameters -

consider parameterized junit test. junit provides way parameterize such test using static method:

@parameterized.parameters public static collection<object[]> parameters(){ object[][] info = new object[][] { { 1, 11 }, { 2, 22 }, { 3, 33 }, { 4, 44 } }; homecoming arrays.aslist(data); }

however, not need, because not know parameters @ test class itself. test class should test class can parameterized set of parameters. not want specify such parameters within class itself. consider have lot of such classes in test suite.

what want able parameterizes whole test suite external code. i.e., have other code instanciates suite specific set of parameters. suite not know parameters parameterized.

e.g., have test suite x consisting of test classes a, b, , c. these classes take, e.g., string , integer in constructor parameters. want able instanciate x externally (e.g., in test suite) specific string s , int i instanciate a b , c using s , i in constructors.

how can achieved?

i'm using junitparams package, adds more abilities parametrize tests. 1 of abilities, specify separate class provides parameters. take @ link, give lot of examples, 1 of them using external class.

java unit-testing junit parameterized-tests

No comments:

Post a Comment