What are some good approaches to separating test data from test scripts?
We're working on test code (mainly UI tests with a few different tools). One thing that's really stumping me is how to best separate test data from test scripts. By test data, I mean values that get input into the AUT.
Currently, I have a bunch of classes that simply contain test data in methods. This almost works but it's
- not scalable and
- not modifiable from outside the test code.
We've discussed some approaches like keeping data in a test data database, where different data are called when needed by scripts. This is likely the way to go, but I have no idea how to implement it. What are some approaches that others have had success with? I'd like to have test scripts as agnostic to incoming data as possible.
EDIT Some more details about these tests: All test data are parameters that are passed from an external source (different classes, xml, database, etc) into the test code. These tests are written in Java.
Demir last edited by user
See if your test framework gives you a way to parameterize tests. Many test frameworks allow you to supply the values using a "data provider" method or object or class that you write yourself. If you have a framework like that, see if you can use its data provider mechanism to supply the values.
The usual mechanism is that your code fetches the values from somewhere, and hands them to the test framework as some sort of grid-like thing (list of lists, array of arrays, iterable of arrays). Each "row" of the grid represents the values for one execution of the test.
This is fairly easy in TestNG, and possible (with a bit of fiddling) in JUnit.
If at all possible, store the values in plain text files. The reason for this is so that you can put the data into version control along with the tests. Often a CSV file will do nicely, and there are likely plenty of CSV-reader libraries for whatever language you're using to automate tests. Any kind of binary data file (Excel, a database, ...) will not play well with version control.