Availability

Child pages
  • Feature - database defined testcases

Skip to end of metadata
Go to start of metadata

Description

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 database tables or CSV files. Actually, any SQL select statement that generates the appropriate result table can be used to generate testcases.

Usage

  • Database table testcase definitions can be included in any GINT testcase
  • At least a short Groovy based test script is still required to run database based testcases
  • A valid SQL connection and select statement is required at test run time
  • Groovy code can be used in any designated column, but is not required
  • All columns necessary for a valid testcase definition must be present
  • 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

Example

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 (smile).

sqlTest.gant

databaseConfig

  • Assume databaseConfig is defined as in the profile example
includeTool << org.swift.tools.SqlHelper  // SQL support utilities
includeTool << org.swift.tools.Gint       // test framework

gint.initialize(this) // required

tableName = 'example'
connection = sqlHelper.getConnection(databaseConfig) 
gint.add(connection, "select * from ${tableName}")

gint.finalizeTest() // final preparations for running tests

SQL data

CREATE TABLE ${tableName} (name text NOT NULL, inline text default 'true');
INSERT INTO ${tableName} VALUES ('name1', 'assert 1 == 1');
INSERT INTO ${tableName} VALUES ('name2', 'def x = "name2"; return (testcase.name == x)'); 

Run

gant -f sqlTest.gant

= = = = = =   sqltest started at Sat Sep 11 20:38:48 CDT 2010   = = = = = =

    [start] name1
    [start] name2
   [ending] name1
 [complete] name1 - 0.018 secs

   [ending] name2
 [complete] name2 - 0.017 secs

     [info] Successful testcases  . . . . . . . . . . : 2    <<< TEST SUCCESSFUL
     [info] Total testcases . . . . . . . . . . . . . : 2
     [info] Elapsed run time  . . . . . . . . . . . . : 1.217 secs

= = = = = =   sqltest completed at Sat Sep 11 20:38:49 CDT 2010 = = = = = =

BUILD SUCCESSFUL
Total time: 2.36 seconds
  • No labels