For some organizations and testing considerations, it is more desirable to have testcases defined in tables instead of code. While some level of testcase scripting may still be necessary, GINT testcase definitions can come from CSV files or database tables. GINT processes CSV files conforming to The Comma Separated Value (CSV) File Format.
- CSV testcase definitions can be included in any GINT testcase
- At least a short Groovy based test script is still required to run CSV based testcases
- Groovy code can be used in any designated column, but is not required
- The first row of the CSV file must be a row of column names
- All columns necessary for a valid testcase definition must be present in the CSV file
- Column names ending with _code are interpreted as Groovy code, the _code is stripped from the column name to form the parameter name
- Column names ending with Closure are turned into Groovy closures with testcase being the only Closure parameter
- inline column, if present, is also handled as a closure
This example is from GINT's own integration test, so is a bit contrived as it was needed to test the capabilities. A more typical example would be command based with little or no Groovy code .
includeTool << org.swift.tools.Gint // test framework
gint.initialize(this) // required
gint.addFromCsv(fileName: gint.getResourceFile('test.csv')) // file from the project's resource directory
gint.finalizeTest() // final preparations for running tests
- First line defines the testcase parameter names
name, inline, someTest_code, level
t1, assert 1 == 1
t2, assert 1 == 2, , false
t3, "def x = ""t3""
return (testcase.name == x)"
t4, "testcase.name; return true",
t5, "assert (testcase.someTest instanceof List); assert testcase.someTest.size() == 2;", "['1', '2']"
invalid will be ignored
gant -f csvTest.gant
= = = = = = csvtest started at Sat Sep 11 18:15:58 CDT 2010 = = = = = =
[warning] Testcase 'invalid will be ignored' does not define cmd or inline code.
[warning] Ignoring testcase: [name:invalid will be ignored, expected:0]
[complete] t1 - 0.071 secs
[complete] t3 - 0.082 secs
[complete] t4 - 0.053 secs
[complete] t5 - 0.051 secs
[info] Successful testcases . . . . . . . . . . : 4 <<< TEST SUCCESSFUL
[info] Not run testcases . . . . . . . . . . . . : 1
[info] Deferred testcases . . . . . . . . . . . : 1
[info] Level of run . . . . . . . . . . . . . . : 1
[info] Deferred levels . . . . . . . . . . . . . : [false]
[info] Total testcases . . . . . . . . . . . . . : 6
[info] Elapsed run time . . . . . . . . . . . . : 0.978 secs
= = = = = = csvtest completed at Sat Sep 11 18:15:58 CDT 2010 = = = = = =
Total time: 2.04 seconds