Tuesday, 3 June 2014

JUnit Parameterized TestCases

Hello,

Last few days I was working on selenium based automation testing. During the development of a framework I came across few interesting elements in JUnit4. Today we are going to talk about running testcases with parameters.

A common scenario

In many situations you might have to create multiple JUnit TestCases which are identical except for the input data. For example, if you want to test a form page with multiple values for the same field, you will end up in creating identical test cases with different input values.

Don't create multiple TestCases

You can get rid of creation of identical testcases with the help of Parameterized runner. I will give the steps for creating a Parameterized test case.

  1. Create your test case
  2. Annotate it with Parameterized                                                                                                           
  3. Create a static method that returns a Collection of Object Array. Also annotate it with Parameters     
  4. Create a constructor with the same number of arguments as given in the array                                          
  5. You are done. Now run the testcase!
You can notice that each test method is executed for each item in that collection. 


Good day!

1 comment:

  1. Excellent and very cool idea and the subject at the top of magnificence and I am happy to this post..Interesting post! Thanks for writing it.What's wrong with this kind of post exactly? It follows your previous guideline for post length as well as clarity.
    Java Training in Chennai

    ReplyDelete