Académique Documents
Professionnel Documents
Culture Documents
Software Testing
Software testing is a critical element of software quality assurance and represents the ultimate review of:
specification design coding
Software life-cycle models (e.g., waterfall) frequently include software testing as a separate phase that follows implementation!
Goals of Testing
Discover and prevent bugs. The act of designing tests is one of the best bug preventers known. (Test, then code philosophy) The thinking that must be done to create a useful test can discover and eliminate bugs in all stages of software development. However, bugs will always slip by, as even our test designs will sometimes be buggy.
Level 0 Thinking
Testing is the same as debugging Does not distinguish between incorrect behavior and mistakes in the program Does not help develop software that is This is what we teach undergraduate CS majors reliable or safe
Level 1 Thinking
Purpose is to show correctness Correctness is impossible to achieve What do we know if no failures?
Good software or bad tests?
Level 2 Thinking
Purpose is to show failures Looking for failures is a negative activity Puts testers and developers into an adversarial relationship
This describes most software companies.
Level 3 Thinking
Testing can only show the presence of failures Whenever we use software, we incur some risk Risk may be small and consequences unimportant Risk may be great and the consequences catastrophic This describes a few enlightened software companies Testers and developers work together to reduce risk
A mental discipline that increases quality Testing is only one way to increase quality Test engineers can become technical leaders of the project Primary responsibility to measure and improve software quality Their expertiseway traditional engineering works This is the should help the developers
Level 4 Thinking
Test Cases
Test cases are formal procedures:
inputs are prepared outcomes are predicted tests are documented commands are executed results are observed
All of these steps are subject to mistakes. Tests may have bugs themselves.
Levels of Testing
Unit Testing: A unit is the smallest testable piece of software (e.g., function). Component Testing: A component is an integrated aggregate of one or more units (e.g., module). Integration Testing: This testing is used to demonstrate that a combination of successfully tested components has bugs.
Testing Oracles
A testing oracle is any program, process, or body of data that specifies the expected outcome of a set of tests. Oracles are often defined as a set of input/expected outcome pairs.
P:D p R
A program specification is the function:
S:Dp R
Input domain is D, output range is R. Proving program correctness is the process of demonstrating that:
P (d ) ! S (d ), d D
Program Testing
Can reveal the presence of faults NOT their absence. A successful test is a test which discovers one or more faults. Only validation technique for nonfunctional requirements. Should be used in conjunction with static verification.
Defect Testing
The objective of defect testing is to discover defects in programs. A successful defect test is a test which causes a program to behave in an anomalous way. Tests show the presence not the absence of defects.
Testing Priorities
Only exhaustive testing can show a program is free from defects. However, exhaustive testing is impossible. Tests should exercise a systems capabilities rather than its components. Testing old capabilities is more important than testing new capabilities. Testing typical situations is more important than boundary value cases.
Testing Effectiveness
In an experiment, black-box testing was found to be more effective than structural testing in discovering defects.
Black-box Testing
Approach to testing where the program is considered as a black-box. The program test cases are based on specifications. Test planning can begin early in the software process.
Black-box Testing
Input test data I
e
System
Oe
Equivalence Partitioning
Invalid inputs Valid inputs
System
Outputs
Input array (T) 17 17 17, 29, 21, 23 41, 18, 9, 31, 30, 16, 45 17, 18, 21, 23, 29, 41, 38 21, 23, 29, 33, 38
Key (Key ) 17 0 17 45 23 25
Structural Testing
Sometime called white-box testing. Derivation of test cases according to program structure. Knowledge of the program is used to identify additional test cases. Objective is to exercise all program statements (not all path combinations).
White-box Testing
Test data
Tests
cla ss Bi nS e a rch { // // // // // // // T h is is a n en ca psulat ion o f a b in a ry s ea rc h fu nc tion th at ta ke s an a rr a y of o rd e red ob je cts a n d a k ey a nd re tu rn s an o bj e ct w ith 2 a ttribu te s na m e ly in de x - t he va lu e of th e a rray in dex fo un d - a b oo le an in dica tin g w h ethe r or no t the k e y is in th e arra y A n ob je ct is re tur ne d be ca use it is n o t po ssib le in J a va to p as s ba si c ty pes by re fe re nc e to a fun ctio n a nd s o re tu rn two va lu es th e ke y is -1 if the e le me nt is n ot fo un d
p ub li c s tatic v o id se arch ( in t k ey , in t [] e lem A rra y, R e su lt r ) { in t bo tto m = 0 ; in t top = e le mA rray .le ng th - 1 ; in t m id ; r.fo un d = f al se ; r.in de x = -1 ; w hile ( b otto m <= top ) { m id = (t op + bo ttom ) / 2 ; if (e le mA rray [m id ] == key ) { r.in de x = m id ; r.fo un d = t ru e ; re tu rn ; } // if p art e ls e { if (e le mA rray [m id ] < k ey ) b ot tom = m id + 1 ; e ls e to p = m id - 1 ; } } //w hile lo op } // se ar ch } //B in Sea rc h
8 5 9
Mid-point