This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Parametrized JUnit test case" Watch "Parametrized JUnit test case" New topic

Parametrized JUnit test case

Gopishankar haridas

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

Joined: Feb 26, 2001
Posts: 6529

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]
I agree. Here's the link:
subject: Parametrized JUnit test case
It's not a secret anymore!