universal automation database solution for sw testing
TRANSCRIPT
Universal Automation Database Solution for SW Testing
Zhang Yu Tao
2015/11/15
• Purpose• Identify the business.• DB design.• Example of DB tables.• Triggers for keeping test data synchronized.• VIEWS (optional).• Use data in Test Case/Script.• Summary• Details of implementation.
Topic
In a software testing, we cannot execute a test without data. If we need data but not manage them, we usually face below pains:
1. The test data is huge and cannot be understand.2. The test data changes, but we do not know which dependent test
would be impacted, I doubt if I should update it.3. I need to update a same data in many places when the data is change.4. I do not know if I can use old data or create new data for my new test.5. I do not know how to use a data/update data of an old test.6. So much duplicate data and what old data is expired?7. I backup all data manually.
Purpose
Identify the business
Test/User
Data File/Database
When add new data, I want to see current data structure and type.
I want to know which data is being used and which one is no longer used .
When execute test, I want get my own validate data.
The business between a Test/User and Data is very simple. After storing the data,why not managing data automatically?
When I update data, I want to know how and where to update.
… …others , but all thing is,• Tester: when execute/update test, I just need myself data and do
not impact other tests, and others do not impact me too.• Manager: I need a clear data list and the data should be readable
and reasonable.
I just store your data, please
enjoy yourself.
TEST_DATA_LISTPK TD_ID
TABLE_NAMETABLE_PK_IDOWNER
Test Data Tables (belongs to business.)Purpose:The tables store all data for testing purpose. The relationship of those tables can be any type that depends on your testing data.
Columns: N/A and no limit that depends on what testing environment you have.
Data Change:• The data of those tables would be changed by user
based on requirement. • The keys between those tables and TEST_DATA_LIST
table is the OWNER ,TABLE_NAME and TABLE_PK_ID.
• When data is changed in those tables, a mechanism should be here for guarantying the data of TEST_DATA_LIST table is synchronized with the change.(We use “trigger” on table to archive the function right now)
DATA_CENTERS Table
VLANS Table “N” Table
TEST_DATA_LIST (belongs to test DB mgmt.)
Purpose:This table is a list which lists all data from the table that “TABLE_NAME” specifies can be used for testing.
Columns:TD_ID: the unique id.TABLE_NAME: the name of table which data would be used for testing(Comes from “Test Data Tables” like DATA_CENTERS table’s name).TABLE_PK_ID: the PK’s id of record of above “TABLE_NAME” specifies.OWNER: the DB user name which the table “TABLE_NAME” belongs to.
Data Change:This table’s data would be automatically generated along with data change of the table that ‘TABLE_NAME’ specifies(use “Trigger” on tables to archive the function right now), or SYS man change the data manually.
TEST_CASE_LIST (belongs to test DB mgmt.)
Purpose:A table store information of test case.
Columns:TC_ID: the unique id.NAME: a name of test case.DES: the description of test case.OWNER: the DB user name which the data belongs to.
Data Change:It would be manually changed by user which testing’s purpose.
TCDR (belongs to test DB mgmt.)
Purpose:A table specifies the relationship between tables TEST_DATA_LIST and TEST_CASE_LIST. This relationship reflects how test case uses the data.
Columns:ID: the unique id.TC_ID: The TC_ID of table TEST_CASE_LIST.TD_ID: the TD_ID of table TEST_DATA_LIST.
Data Change:It would be manually changed by user which testing’s purpose.
TCDRPKFK1FK2
IDTC_IDTD_ID
TEST_CASE_LISTPK TC_ID
NAMEDESOWNER
DATA_CENTERSPK DC_ID
NAMEDES
VLANSPK VLAN_ID
NAMEDC_ID
Trigger
Trigger
DB Design (base on Oracle 11g r2)
Example of DB tables
DATA_CENTERSDC_ID
NAME DES
1 dc01 US2 dc02 UK
TEST_DATA_LISTTD_ID TABLE_NAME TABLE_PK_I
DOWNER
1 DATA_CENTERS 1 xx2 DATA_CENTERS 2 xx3 VLANS 1 xx4 VLANS 2 xx
VLANSVLAN_ID NAME DC_ID1 vl01 12 vl02 2
TEST_CASE_LISTTC_ID
NAME DES OWNER
1 case01
xx xx
2 case02
xx xx
3 case03
xx xx
4 case04
xx xx
TCDRID
TC_ID TD_ID
1 1 12 1 33 3 24 3 4
Trigger Trigger
Test DB Manager
Business DB Tables
*The tables of the two types belongs to different DB user in order to let the DB support any business test data requirement. For example, if you have a product, you want to test it in different environment, or you have more products with different business data, so you only need one “Test DB Manager” to process all “Business DB tables”.
Triggers for keeping test data synchronized
CREATE OR REPLACE TRIGGER "AFTER_CHANGE_DATA_CENTERS" AFTER INSERT ON DATA_CENTERS
FOR EACH ROW
DECLARE
v_find number;
v_series number;
BEGIN
CASE
WHEN inserting THEN
SELECT COUNT(*) INTO v_find FROM TEST_DATA_LIST WHERE TABLE_NAME='DATA_CENTERS' AND TABLE_PK_ID=:NEW.DC_ID;
IF v_find=0 THEN
SELECT COUNT(*) INTO v_series FROM TEST_DATA_LIST;
INSERT INTO TEST_DATA_LIST VALUES(v_series+1,'DATA_CENTERS',:NEW.DC_ID );
End IF;
End CASE;
END;
CREATE OR REPLACE TRIGGER "BEFORE_CHANGE_DATA_CENTERS" BEFORE UPDATE OR DELETE ON DATA_CENTERS FOR EACH ROW
DECLARE
v_count number;
BEGIN
CASE
WHEN updating THEN
IF :OLD.DC_ID<>:NEW.DC_ID THEN
SELECT COUNT(*) INTO v_count from TEST_DATA_LIST where TABLE_NAME='DATA_CENTERS' and TABLE_PK_ID = :OLD.DC_ID;
IF v_count > 0 THEN
raise_application_error(-20001,'DC_ID "'||:OLD.DC_ID||'" is used in TEST_DATA_LIST');
END IF;
END IF;
WHEN deleting THEN
SELECT COUNT(*) INTO v_count from TEST_DATA_LIST where TABLE_NAME='DATA_CENTERS' and TABLE_PK_ID = :OLD.DC_ID;
IF v_count > 0 THEN
raise_application_error(-20001,'DC_ID "'||:OLD.DC_ID||'" is used in TEST_DATA_LIST');
END IF;
End CASE;
END;
The triggers would be setup on “test data tables” to guaranty data of TEST_DATA_LIST synchronized is valid when data happens updating/inserting/deleting.
• Example:
the trigger for generating data in TEST_DATA_LIST table after DATA_CENTERS table is inserted a new data:
• Example:
the trigger for voiding update/delete data in DATA_CENTERS table if this data have been used in TEST_DATA_LIST table:
VIEWS (Optional)
V_TEST_CASE_LIST_DETAILS: show all test case with what data it is using.
V_TEST_DATA_LIST_DETAILS:show all data can be used in test and the relationship between tables.
The VIEWS is useful for understanding how the test data is used.
V_TEST_CASE_LIST_DETAILSTC_ID
TC_NAME TD_ID TABLE_NAME TABLE_PK_ID
IDENTIFIER
1 case01 1 DATA_CENTERS 1 dc012 case01 3 VLANS 1 vl013 case03 2 DATA_CENTERS 2 dc024 case03 4 VLANS 2 vl02
V_TEST_DATA_LIST_DETAILSTD_ID
TABLE_NAME TABLE_PK_ID IDENTIFIER PARENT_TD_ID
1 DATA_CENTERS
1 dc01 1
2 DATA_CENTERS
2 dc02 2
3 VLANS 1 vl01 14 VLANS 2 vl02 2
Use data in Test Case/Script
DATA_CENTERSDC_ID
NAME DES
1 dc01 US2 dc02 UK
Step1: Setup test data tables according to your business.
VLANSID NAME DES1 dc01 US2 dc02 UK
xxxxxxID NAME DES1 dc01 US2 dc02 UK
……
File 1<TESTDATA ENV="DEMO" TESTNAME="fill your value here(len<500)" DES="fill your value here(len<500)" AUTHOR="fill your value here(len<100)">
<TABLE NAME="DATA_CENTERS"> <ROWS> <ROW> <COL NAME="DC_ID" TYPE="NUMBER">fill your value here</COL> <COL NAME="NAME" TYPE="VARCHAR2">fill your value here</COL> <COL NAME="DES" TYPE="VARCHAR2">fill your value here</COL> </ROW> </ROWS> <CONSTRAINTS> <CONSTRAINT TYPE="C" COL="DC_ID"/> <CONSTRAINT TYPE="C" COL="NAME"/> <CONSTRAINT TYPE="P" COL="DC_ID"/> <CONSTRAINT TYPE="U" COL="NAME"/> </CONSTRAINTS></TABLE>
<TABLE NAME="VLANS"> <ROWS> <ROW> <COL NAME="VLAN_ID" TYPE="NUMBER">fill your value here</COL> <COL NAME="NAME" TYPE="VARCHAR2">fill your value here</COL> <COL NAME="DC_ID" TYPE="NUMBER">fill your value here</COL> <COL NAME="DES" TYPE="VARCHAR2">fill your value here</COL> </ROW> </ROWS> <CONSTRAINTS> <CONSTRAINT TYPE="C" COL="VLAN_ID"/> <CONSTRAINT TYPE="C" COL="NAME"/> <CONSTRAINT TYPE="C" COL="DC_ID"/> <CONSTRAINT TYPE="P" COL="VLAN_ID"/> <CONSTRAINT TYPE="R" COL="DC_ID" R_TABLE_NAME="DATA_CENTERS" R_COLUMN_NAME="DC_ID"/> </CONSTRAINTS></TABLE>
</TESTDATA>
Use data in Test Case/Script
Step2: Prepare your data of test.
There would be a common function can be invoked by user to download all the relationships of DB tables and any data of any test to a file(.xml,.json…) like “File 1” and “File 2”.
Follow the downloaded file like “File 2” to write own data file and then to upload to DB.
File 2<TESTDATA ENV="DEMO" TESTNAME="TEST1"><TABLE NAME="DATA_CENTERS"> <ROWS> <ROW> <COL NAME="DC_ID">1</COL> <COL NAME="NAME">DC-ForAT</COL> <COL NAME="DES">DC for AT</COL> </ROW> </ROWS> </TABLE><TABLE NAME="VLANS"> <ROWS> <ROW> <COL NAME="VLAN_ID">1</COL> <COL NAME="NAME">VLAN-ForAT</COL> <COL NAME="DC_ID">1</COL> <COL NAME="DES">VLAN for AT</COL> </ROW> </ROWS> </TABLE></TESTDATA>
*The “File 2” is the data which is used in your test, so the DB should store the uploaded “File 2” with its data sequence in order to keep the download “File 2” is same to it was uploaded.
Use data in Test Case/Script
Step3: Upload data of a test to all data tables.
*There would be a common function in DB to handle it.
Step4: Query data from data tables and return to the caller from test/user.
*There would be a common function in DB to handle it.
These two steps should be automated run by DB.
SummaryPurpose Solution provided
The test data is huge and cannot be understand.
The data in DB has own relationship and each data can be annotated.
The test data changes, but we do not know which dependent test would be impacted, I doubt if I should update it.
DB can provide a view for all current dependencies between test data and test case.
I need to update a same data in many places when the data is change.
A simple SQL can update all such data.
I do not know if I can use old data or create new data for my new test.
DB can provide a template for the structure of current test data tables, you just need to follow the template to fill the data your need to upload to DB. DB will automatically decide if insert new data or use old data. The result is what file you uploaded what file you will get from DB.
I do not know how to use a data/update data of an old test.
Same to above
I backup all data manually. Easy to DB
So much duplicate data and what old data is expired?
DB can provide a view for all current dependencies between test data and test case. Then you can use SQL to take it.
• DB automatically decide if the data you uploaded is duplicate or new or need to update in DB.
• DB provide template to you to fill your new data for later uploading.
• DB provide a file of old data to you to update the data for later uploading.
• The data used in test is the same to the data you uploaded (including the data’s sequence which keep the data invoking in your test not impacted).
Details of implementationThe code for automatically creating the database, please contact me, [email protected].