Anda di halaman 1dari 37

Testing Database-Driven Applications: Challenges and Solutions

Gregory M. Kapfhammer Department of Computer Science University of Pittsburgh Department of Computer Science Allegheny College Mary Lou Soffa Department of Computer Science University of Pittsburgh

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 1/32

Outline
Introduction and Motivation Testing Challenges Database-Driven Applications A Unied Representation Test Adequacy Criteria Test Suite Execution Test Coverage Monitoring Conclusions and Resources
Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 2/32

Motivation
The Risks Digest, Volume 22, Issue 64, 2003
Jeppesen reports airspace boundary problems
About 350 airspace boundaries contained in Jeppesen NavData are incorrect, the FAA has warned. The error occurred at Jeppesen after a software upgrade when information was pulled from a database containing 20,000 airspace boundaries worldwide for the March NavData update, which takes effect March 20.

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 3/32

Testing Challenges
Should consider the environment in which software applications execute Must test a program and its interaction with a database Database-driven applications state space is well-structured, but innite (Chays et al.) Need to show program does not violate database integrity, where integrity = consistency + validity (Motro) Must locate program and database coupling points that vary in granularity

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 4/32

Testing Challenges
The structured query languages (SQL) data manipulation language (DML) and data denition language (DDL) have different interaction characteristics Database state changes cause modications to the program representation Different kinds of test suites require different techniques for managing database state during testing

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 5/32

Testing Challenges
The many testing challenges include, but are not limited to, the following: Unied program representation Family of test adequacy criteria Efcient test coverage monitoring techinques Intelligent approaches to test suite execution

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 6/32

Database-Driven Applications
P
A B

R1
C D

mi Dk
E F

R2
G H

mj

R3
I J K L

Dl

Program P interacts with two relational databases


Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 7/32

Database Interaction Levels


D1

P
Dn
Database Level

A program can interact with a database at different levels of granularity


Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 8/32

Database Interaction Levels


D1

P
Dn
1 2 3 4

UserInfo
card_number pin_number user_name acct_lock

32142 41601 45322 56471

Brian Zorman Robert Roos Marcus Bittman Geoffrey Arnold

0 0 0 0

Relation Level

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 8/32

Database Interaction Levels


D1

P
Dn
1 2 3 4

UserInfo
card_number pin_number user_name acct_lock

32142 41601 45322 56471

Brian Zorman Robert Roos Marcus Bittman Geoffrey Arnold

0 0 0 0

Record Level

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 8/32

Database Interaction Levels


D1

P
Dn
1 2 3 4

UserInfo
card_number pin_number user_name acct_lock

32142 41601 45322 56471

Brian Zorman Robert Roos Marcus Bittman Geoffrey Arnold

0 0 0 0

Attribute Level

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 8/32

Database Interaction Levels


D1

P
Dn
1 2 3 4

UserInfo
card_number pin_number user_name acct_lock

32142 41601 45322 56471

Brian Zorman Robert Roos Marcus Bittman Geoffrey Arnold

0 0 0 0

Attribute Value Level

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 8/32

Database Interaction Points


Database interaction point Ir I corresponds to the execution of a SQL DML statement Consider a simplied version of SQL and ignore SQL DDL statements (for the moment) Interaction points are normally encoded within Java programs as dynamically constructed Strings uses Dk , delete denes Dk , insert denes Dk , update denes and/or uses Dk
select

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 9/32

Database Interaction Points (DML)


select A1 , A2 , . . . , Aq from r1 , r2 , . . . , rm where Q insert into r(A1 , A2 , . . . , Aq ) values(v1 , v2 , . . . , vq ) delete from r where Q

update r set Al = F (Al ) where Q

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 10/32

Rened Database-Driven Application


P mi Dk
E F

select * from R1 where A < (select avg(G) from R2 )

R1
A B C D

R2
G H

mj

R3
I J K L

Dl
update R3 set J = 500 where L < 1000

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 11/32

Test Adequacy Criteria


P violates a database Dk s validity when it: inserts entities into Dk that do not reect real world
(1-v)

P violates a database Dk s completeness when it: deletes entities from Dk that still reect real world
(1-c)

In order to verify (1-v) and (1-c), T must cause P to dene and then use entities within D1 , . . . , Dn !

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 12/32

Data Flow Information


Interaction point: UPDATE UserInfo SET acct lock=1 WHERE card number= + card number + ;;
Database Level: dene(BankDB) Attribute Level: dene(acct_lock) and use(card_number)

Data ow information varies with respect to the granularity of the database interaction

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 13/32

Database Entities
UserInfo
card_number pin_number user_name acct_lock

1 2 3 4

32142 41601 45322 56471

Brian Zorman Robert Roos Marcus Bittman Geoffrey Arnold

0 0 0 0

Av(Ir ) = {

32142

, . . . , Geoffrey Arnold ,

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 14/32

The DICFG: A Unied Representation


entry lockAccount

temp1 = parameter0:c_n temp2 = LocalDatabaseEntity0:Bank temp3 = LocalDatabaseEntity1:acct_lock temp4 = LocalDatabaseEntity2:card_number

Database-enhanced CFG for lockAccount Dene temporaries to represent the programs interaction at the levels of database and attribute

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 15/32

The DICFG: A Unied Representation


qu_lck = "UPDATE UserInfo ..." + temp1 + ";" update_lock = m_connect.createStatement()

entry Gr 2 define(temp3) use(temp4)


exit Gr 2

entry Gr 1 define(temp2) exit G r 1

Database interaction graphs (DIGs) are placed before interaction point Ir Multiple DIGs can be integrated into a single CFG
String at Ir is determined in a control-ow sensitive fashion

Ir

result_lock = update_lock.executeUpdate(qu_lck) if( result_lock == 1) completed = true exit lockAccount

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 15/32

Test Adequacy Criteria


Database interaction association (DIA) involves the def and use of a database entity DIAs can be located in the DICFG with data ow analysis all-database-DUs requires tests to exercise all DIAs for all of the accessed databases

allattributevalueDUs

allrecordDUs

allattributeDUs

allrelationDUs

alldatabaseDUs

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 16/32

Generating Test Requirements


Relational Schema Database Seeder
Database

Measured time and space overhead when computing family of test adequacy criteria
(C)

System Under Test

Test Adequacy Criterion

(P)

Modied ATM and mp3cd to contain appropriate database interaction points Soot 1.2.5 to calculate intraprocedural associations GNU/Linux workstation with kernel 2.4.18-smp and dual 1 GHz Pentium III Xeon processors

Test Case Specification

Test Requirements

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 17/32

Counting Associations and Denitions


Assoc & Def Count D 1750 1500 1250 1000 750 500 250 0 D Rc Rl A Av Database Granularity Rc Rl A Av
ATM DB mp3cd DB ATM HD mp3cd HD

DIAs at attribute value level represent 16.8% of mp3cds and 9.6% of ATMs total number of intraprocedural associations

p. 18/32

Measuring Time Overhead


Time Overhead None D Rc Rl A 37.5 35 32.5 30 27.5 25 22.5 None D Rc Rl A Av Database Granularity Av
ATM mp3cd

Computing DIAs at the attribute value level incurs no more than a 5 second time overhead

System Time

sec

p. 19/32

Measuring Average Space Overhead


None 30 28 26 24 22 20 18 16 None D Node & Edge Count Rc Rl A Av
Natm Nmp3 Eatm Emp3

D Rc Rl A Av Database Granularity

mp3cd shows a more marked increase in the average number of nodes and edges than ATM

p. 20/32

Measuring Maximum Space Overhead


Node & Edge Count None 1400 1200 1000 800 600 400 200 None D Rc Rl A Av Database Granularity D Rc Rl A Av
Natm Nmp3 Eatm Emp3

mp3cd shows a signicantly greater maximum space overhead than ATM

p. 21/32

Automatic Representation Construction


Manual construction of DICFGs is not practical Use extension of BRICS Java String Analyzer (JSA) to determine content of String at Ir Per-class analysis is inter-procedural and control ow sensitive Conservative analysis might determine that all database entities are accessed Include coverage monitoring instrumentation to track DIGs that are covered during test suite execution

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 22/32

Tracking Covered DIGs and DIAs


PDB
1

DIG r

mi
2

DIG Coverage Table


DIG # DEF 1 { ... } q { ... } USE TEST COV? { ... } { ... } { ... } { ... }

DIG s
1

mj
2

DIA coverage can be tracked by recording which DIGs within a DICFG were executed during testing
Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 23/32

Types of Test Suites


0

0 T1 m1 1 e1 Te me e
Independent

T1

m1 1 1

0 T1 m1 1 e1 Te me e
Non-restricted
p. 24/32

m e

Te

me e

Partially Independent

Test Suite Execution


Independent test suites can be executed by using provided setup code to ensure that all = 0 Non-restricted test suites simply allow state to accrue Partially independent test suites must return to after T is executed by : 1. Re-executing all SQL statements that resulted in the creation of 2. Creating a compensating transaction to undo the SQL statements executed by each test after T

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 25/32

Representation Extension
The execution of a SQL insert during testing requires the re-creation of DICFG(s) The SQL delete does not require re-creation because we must still determine if deleted entity is ever used DICFG re-creation only needed when database interactions are viewed at the record or attribute-value level Representation extension ripples to other methods DICFGs can be re-constructed after test suite has executed, thus incurring smaller time overhead
Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 26/32

Test Coverage Monitoring


For each tested method mi that interacts with a database and each interaction point Ir that involves an insert we must:
1. Update the DICFG 2. Re-compute the test requirements

We can compute the set of covered DIAs by consulting the DIG coverage table Test adequacy is : # covered DIAs / # total DIAs

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 27/32

Calculating Adequacy
Tf
Test Requirements

mi mj
Test Requirements

mi

mj

DIA COV? <def(e1), use(e1)> <def(e2), use(e2)> <def(e3), use(e3)> <def(e4), use(e4)>

DIA COV? <def(e5), use(e5)> <def(e6), use(e6)> <def(e7), use(e7)> <def(e8), use(e8)> <def(e9), use(e9)> <def(e10), use(e10)>
4 6

cov(mi ) =

2 4

cov(mj ) =

cov(Tf ) =

6 10

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 28/32

Related Work
Jin and Offutt and Whittaker and Voas have suggested that the environment of a software system is important Chan and Cheung transform SQL statements into C code segments Chays et al. and Chays and Deng have created the category-partition inspired AGENDA tool suite Neufeld et al. and Zhang et al. have proposed techniques for database state generation Dauo et al. focused on the regression testing of database-driven applications
Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 29/32

Conclusions
Must test the programs interaction with the database Many challenges associated with (1) unied program representation, (2) test adequacy criteria, (3) test coverage monitoring, (4) test suite execution The DICFG shows database interactions at varying levels of granularity Unique family of test adequacy criteria to detect type (1) violations of database validity and completeness Intraprocedural database interactions can be computed from a DICFG with minimal time and space overhead
Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 30/32

Conclusions
Test coverage monitoring instrumentation supports the tracking of DIAs executed during testing Three types of test suites require different techniques to manage the state of the database SQL insert statement causes the re-creation of the representation and re-computation of test requirements Data ow-based test adequacy criteria can serve as the foundation for automatically generating test cases and supporting regression testing

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 31/32

Resources
Gregory M. Kapfhammer and Mary Lou Soffa. A Family of Test Adequacy Criteria for Database-Driven Applications. In FSE 2003. Gregory M. Kapfhammer. Software Testing. CRC Press Computer Science Handbook. June, 2004.
http://cs.allegheny.edu/gkapfham/research/diatoms/

Database drI ven Application T esting tOol ModuleS , IBM T.J. Watson Research Center, May 14, 2004 p. 32/32

Anda mungkin juga menyukai