This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 4442
    
    5

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]
 
Consider Paul's rocket mass heater.
 
subject: Parametrized JUnit test case
 
Similar Threads
JUNIT and writting test case for MDB
Junit with XML inputs
Testing Message driven bean in Junit
JUnit Testing
Ho do we select Interesting values for a test case?