views:

165

answers:

1

Hello,

I am new to eclipse. I am using JUnit 4. and i have written a set up method in my class which extends Testcase where some initialization happens. I have some set of testcases in the same class. I have test data in zipped form and attached to work space. Currently i am able to run all test cases for a single test data. Somehow i want the control to go back to set up() to take second test data and run all the test cases. Is it possible? ans if yes can anyone please send some code snippet?

Thanks in advance

Thanks for the reply but where should i keep such code whether it should be kept in set up method and how test data will be taken up from set up?

+1  A: 

You need to use the Parameterized runner. It allows you to run the same test with multiple test data. e.g. The following will imply that the tests will run four times, with the parameter "number" changed each time to the value in the array.

@RunWith(value = Parameterized.class)
public class StackTest {
 Stack<Integer> stack;
 private int number;

 public StackTest(int number) {
   this.number = number;
 }

 @Parameters
 public static Collection data() {
   Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 } };
   return Arrays.asList(data);
 }
 ...
}

Edit

Not sure what isn't clear, but I'll attempt to clarify.

The @RunWith(value = Parameterized.class) annotation is required. You must have a method annotated with @Parameters that returns a Collection object, each element of which must be an Array of the various parameters used for the test. You must have a public constructor that will accept these parameters.

Additional information, and another example can be found in the documentation.

Even more examples.

hobodave
Thanks, But where to write these under Setup() method? and if yes then what will be the flow of control?
Can you post your test class?
hobodave