PlugIns JdbcSlim UserGuide 2KeyBenefits
To test that code is working it is not enough to check that the code changed the expected data.
It must also be tested that no other data got changed.
JdbcSlim[?] supports this in the following way.
Going back to our initial example where Ben and Sarah moved location.
Additional we want to check that no other user got moved.
Define the query
Define Properties | SideEffectCheck |
key | value |
.include | TestDatabase |
cmd | select * from TestData where Name not in ('Ben', 'Sarah') |
# | The 'query' flag below tells SQL Command that this statement will return more than one row |
query | true |
Store the data of the other people before the test
Script | SQLCommand | SideEffectCheck |
open connection | ||
execute | ||
$RSBefore= | resultSheet | |
close connection |
Run the test
Included page: .PlugIns.JdbcSlim.UserGuide.1ASimpleExample
Most Tests require three steps.
1. Preparing test data
2. Execution some business functions
3. Validating the impact on the test data
Lets assume we have a database with some information about people and a we need to test a business function that relocates a person into a new city.
To avoid side effects we execute the test in a transaction
To prepare test data two approaches are possible:
1.1 Inserting new data into a database
1.2 Finding suitable existing data in the database
In this examples we use the second approach and find the ID of users named Ben and Sarah which should move.
We store the Id of the users in a Slim Symbol '$TestID' for future reference.
Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris
Here calls to your business code will go.
A simple update statement which can do the job is given below.
Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo
1. Preparing test data
2. Execution some business functions
3. Validating the impact on the test data
Lets assume we have a database with some information about people and a we need to test a business function that relocates a person into a new city.
1 Preparing test data
To avoid side effects we execute the test in a transaction
Script | SQLCommand | TransactionDatabase |
open Connection | ||
execute | begin transaction |
To prepare test data two approaches are possible:
1.1 Inserting new data into a database
1.2 Finding suitable existing data in the database
In this examples we use the second approach and find the ID of users named Ben and Sarah which should move.
We store the Id of the users in a Slim Symbol '$TestID' for future reference.
SQLCommand | TransactionDatabase | select ID, NAME from TestData where Name ='%NAME%' |
ID? | NAME | |
$TestID1= | Ben | |
$TestID2= | Sarah |
Before we proceed we validate that Ben and Sarah still live in the old Cities: Denver and Paris
SQLCommand | TransactionDatabase | select City from TestData where ID ='%ID%' |
ID | CITY? | |
$TestID1 | Denver | |
$TestID2 | Paris |
Execution some business functions
Here calls to your business code will go.
A simple update statement which can do the job is given below.
SQLCommand | TransactionDatabase | update TestData set City='%NewCITY%' where ID ='%ID%' | |
ID | NewCITY | Count? | |
$TestID1 | HongKong | 1 | |
$TestID2 | Tokyo | 1 |
Validating the impact on the test data
Finally we check that Ben now lives in Hong Kong and Sarah in Tokyo
SQLCommand | TransactionDatabase | select City from TestData where ID ='%ID%' |
ID | CITY? | |
$TestID1 | HongKong | |
$TestID2 | Tokyo |
Rollback the change to not impact future tests
Script | SQLCommand | TransactionDatabase |
open Connection | ||
execute | rollback | |
close Connection |
Check that the rollback worked
SQLCommand | TransactionDatabase | select City from TestData where ID ='%ID%' |
ID | CITY? | |
$TestID1 | Denver | |
$TestID2 | Paris |
Contents:
Compare the data of the other people after the test.
Script | SQLCommand | SideEffectCheck |
open connection | ||
execute | ||
$RSAfter= | resultSheet | |
$RSDiff= | compareSheet | $RSBefore |
close connection |
Table:SheetEcho | $RSDiff |