Solution for parameterized tests
I am familiar with using Parameterized Tests in JUnit, for example:
http://junit.org/apidocs/org/junit/runners/Parameterized.html
but I wondered if there are any alternative (possibly more efficient) approaches to external test data. I really don't want to hard-code my test data into the original file - I'd rather define it in XML or some other way.
Is there a specific framework or extension for the framework that provides me with a better solution than the standard JUnit approach. What exactly was the best approach you found to this?
EDIT: I am familiar with the FIT base and its use in this case, I want to avoid this if possible. If there is a JUnit extension or similar framework that provides a better solution than TestNG, please let me know.
a source to share
So I found the TestNG approach for this, which allows you to specify parameters for tests, more details can be found here:
http://testng.org/doc/documentation-main.html#parameters-testng-xml
An example of this would be:
@Parameters({ "first-name" })
@Test
public void testSingleString(String firstName) {
System.out.println("Invoked testString " + firstName);
assert "Cedric".equals(firstName);
}
and
<suite name="My suite">
<parameter name="first-name" value="Cedric"/>
<test name="Simple example">
You can also use a datasource (like Apache Derby) to specify this test information, I wonder how flexible this solution is.
a source to share
I don't see anything in a parameterized test case that requires you to store data in the class itself. Use a method that fetches data from xml file and returns Object [] [] and calls this when they use static code in the example. If you want to switch TestNG, of course they already wrote an XML parser for you. It looks like JUnitExt has one for JUnit 4, or you could write one of your own.
a source to share