Feature - Profiles
Description
Profiles are property files used for providing parameters and settings for testcases. Externalizing these parameters makes it possible to re-use information across multiple tests. It also enables users to separate definitional elements from programming scripts. User can use their own property files or GINT properties, however, GINT profile handling isautomatic and more advanced than simple property files. Profiles are loaded after GINT properties in gint.initialize processing.
- Profiles are identified by a simple name without qualification or extension
- Profiles are property files found by looking up files in a directory search list
- Property file name is the profile name plus '.properties'
- Search list defaults to a directory list based on user, project, and current directory settings or can be explicitly set in code, on the command line, or in gint.properties.
- First file matching the profile name (with .properties extension) is used
- All properties in the property file become global variables available in the test script
- ANT property expansion is used - properties can be referenced in other properties
- First property of a given name will be used, duplicates are ignored
- Properties can be evaluated as Groovy code using a naming convention
- Names ending in _code are evaluated and become variables with the prefix as the variable name
- Example below: databaseConfig_code becomes the variable databaseConfig with value being a Groovy Map.
Example
profileExample.gant
includeTool << org.swift.tools.Helper // Helper utilities includeTool << org.swift.tools.SqlHelper // SQL support utilities includeTool << org.swift.tools.Gint // test framework gint.initialize(this) // required helper.logVarWithFormat('databaseConfig') // requires profile(s) to define this variable! gint.add([name: 'getConnection', inline: { assert null != sqlHelper.getConnection(databaseConfig) } ]) gint.finalizeTest() // final preparations for running tests
profileExample1.properties
databaseHost = 127.0.0.1
profileExample2.properties
# Example # - note that property values can be overridden by an early profile, like in the user's home directory # - this may be necessary for user or system specific configuration information like users and passwords databaseHost = localhost # Note already defined properties will be automatically expanded using the ${...} syntax exampleDatabase = gint exampleDatabaseHost = ${databaseHost} exampleDatabaseUser = gint exampleDatabasePassword = gint exampleDatabaseType = postgresql # Configuration suitable for use by SqlHelper function getConnection # - note this is an example of property that is automatically converted to a groovy map with name databaseConfig # - the ending \ is property file syntax for line continuation databaseConfig_code = [ \ database: '${exampleDatabase}', \ type: '${exampleDatabaseType}', \ host: '${exampleDatabaseHost}', \ user: '${exampleDatabaseUser}', \ password: '${exampleDatabasePassword}', \ ]
Runs
First property setting wins!
Host value is 127.0.0.1 coming from first property file.
gant -f src/itest/resources/profileExample.gant -Dprofiles=profileExample1,profileExample2 = = = = = = profileexample started at Sat Sep 11 10:19:39 CDT 2010 = = = = = = [info] databaseConfig.database . . . . . . . . . : gint [info] databaseConfig.type . . . . . . . . . . . : postgresql [info] databaseConfig.host . . . . . . . . . . . : 127.0.0.1 [info] databaseConfig.user . . . . . . . . . . . : gint [info] databaseConfig.password . . . . . . . . . : gint [start] getConnection [ending] getConnection [complete] getConnection - 0.194 secs [info] Successful testcases . . . . . . . . . . : 1 <<< TEST SUCCESSFUL [info] Total testcases . . . . . . . . . . . . . : 1 [info] Elapsed run time . . . . . . . . . . . . : 0.904 secs + = = = = = profileexample completed at Sat Sep 11 10:19:39 CDT 2010 = = = = = = BUILD SUCCESSFUL Total time: 2.02 seconds
Only use second profile
Host value is now localhost instead of 127.0.0.1.
gant -f src/itest/resources/profileExample.gant -Dprofiles=profileExample2 = = = = = = profileexample started at Sat Sep 11 10:21:11 CDT 2010 = = = = = = [info] databaseConfig.database . . . . . . . . . : gint [info] databaseConfig.type . . . . . . . . . . . : postgresql [info] databaseConfig.host . . . . . . . . . . . : localhost [info] databaseConfig.user . . . . . . . . . . . : gint [info] databaseConfig.password . . . . . . . . . : gint [start] getConnection [ending] getConnection [complete] getConnection - 0.329 secs [info] Successful testcases . . . . . . . . . . : 1 <<< TEST SUCCESSFUL [info] Total testcases . . . . . . . . . . . . . : 1 [info] Elapsed run time . . . . . . . . . . . . : 1.048 secs = = = = = = profileexample completed at Sat Sep 11 10:21:11 CDT 2010 = = = = = = BUILD SUCCESSFUL Total time: 2.19 seconds
© 2005 -2024 gint.org