Assert SQL
This command is not part of the Default Command Set. You have to register the SQL Command Set first (see Configuration).
Executes the given SQL query against the configured database and asserts that the result matches the expected value.
The result is built by concatenating all column values of all rows, separated by spaces.
Parameters
sql-query
The SQL SELECT statement to execute (required).
To target a specific database connection, prefix the SQL with '@[db-name] ', e.g. '@mydb SELECT ...'. If no prefix is given, the default connection is used.
To target a specific database connection, prefix the SQL with '@[db-name] ', e.g. '@mydb SELECT ...'. If no prefix is given, the default connection is used.
expected-result
The expected result as a content pattern (required).
The result is checked using the same pattern syntax as assert-content. It is possible to use '*' and '?' as wildcards.
The result is checked using the same pattern syntax as assert-content. It is possible to use '*' and '?' as wildcards.
Examples
Config (wetator.config)
wetator.commandSets=org.wetator.commandset.SqlCommandSet
wetator.db.connections=mydb
wetator.db.mydb.driver=org.hsqldb.jdbcDriver
wetator.db.mydb.url=jdbc:hsqldb:mem:testdb
wetator.db.mydb.user=sa
wetator.db.mydb.password=
wetator.db.connections=mydb
wetator.db.mydb.driver=org.hsqldb.jdbcDriver
wetator.db.mydb.url=jdbc:hsqldb:mem:testdb
wetator.db.mydb.user=sa
wetator.db.mydb.password=
Assert the count of rows in a table
| Command | Parameter | Optional Parameter | |
|---|---|---|---|
| assert-sql | SELECT COUNT(*) FROM users | 5 |
Assert the value of a specific column
| Command | Parameter | Optional Parameter | |
|---|---|---|---|
| assert-sql | SELECT name FROM users WHERE id = 1 | dobby |
