aspose file tools*
The moose likes Testing and the fly likes Parametrized JUnit test case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Parametrized JUnit test case" Watch "Parametrized JUnit test case" New topic
Author

Parametrized JUnit test case

Gopishankar haridas
Greenhorn

Joined: Aug 30, 2012
Posts: 1
I am trying to create a parametrized test case using JUnit. It should read all parameters in a file say XML. Later have to popup the form for selecting the parameters at run time and then to display things after filtering. I am confused as there is no proper explanation available. Please give me a suggestion or any sample snippets to get me an idea of how to start. I dont wanna give the parameters hard coded in the JUnit test case and i want to use GUI framework like Swing to display it as a form instead of command line parameters..

Please help me in this..


Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4742
    
    7

A few things:
1. What you're planning to do is contrary to the goal of automated testing because you are requiring user intervention via a GUI - now your tests cannot be run unattended.
2. Reading from an XML file makes your test run slower -- this is not going to be a very good unit test since it crosses a system boundary by accessing the file system. It's fine for a test to read from the file system but then it should be run with the set of integration tests, not as a unit test.
3. If you really need to allow the user to do something before you run the tests, then create a separate program that presents the GUI and reads the XML file. Once the user makes his/her selection, then you can programmatically run JUnit, specifying the user-selected parameters as if they were command line parameters. That way you can have your GUI and still write the test per normal JUnit test conventions. I still think there's something fundamentally wrong with your approach if you need to have a user intervene.

And welcome to the Ranch!


Junilu - [How to Ask Questions] [How to Answer Questions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Parametrized JUnit test case