680 likes | 816 Views
Software testing Lecture p8 T120B029 20 12 pavasario sem. Motivation. “ Testing is the process of executing a program with the intent of finding errors”. Limits of software testing. “Good” testing will find bugs
E N D
Software testing Lecture p8T120B0292012 pavasario sem.
Motivation “ Testing is the process of executing a program with the intent of finding errors”
Limits of software testing • “Good” testing will find bugs • “Good” testing is based on requirements,i.e. testing tries to find differences between the expected and the observed behavior of systems or their components • BUT: Testing can only prove the presence of bugs - never their absence
Test Specification - Manual Process Test Cases Test Document Inspection Manual Manual Manual Text-based
Semi-Automated Process Test Cases Test Document Inspection Semi- Automated Automated Manual Model-based Consistency SyntaxSemantic
The V-model Requirements Definition I Acceptance Level Testing Functional system Design System Level Testing II Construction phasess Testing phasess III Integration Level Testing Technical system Design IV Component Specification Unit Level Testing Implementation
The W-model I Preparation of Acceptance Level Testing Acceptance Level Testing Debuging Preparation of System Level Testing System Level Testing II Preparation of Integration Level Testing Construction phasess Integration Level Testing III Preparation of Unit Level Testing IV Unit Level Testing Implementation
Using UML and UTP in system development UML UTP TTCN Debuging I II UML UTP TTCN Debuging UML Junit&TTCN III UTP Debuging IV UML UTP JUnit Debuging Implementation Changes
loop < 20x Exhaustive testing There are 1014 possible paths! If we execute one test per millisecond, it would take 3.170 years to test this program!! Out of question
Testability = how easy can a program be tested Features that help/influence testing: • operability - it operates cleanly • observability • the results are easy to see • distinct output is generated for each input • incorrect output is easily identified • controllability • processing can be controlled • tests can be automated & reproduced • decomposability - software modules can be tested independently • simplicity - no complex architecture and logic • stability - few changes are requested during testing • understandability - program is easy to understand
developer independenttester Who tests the software Understands the system but, will test “gently” and, is driven by “delivery” Must learn about the system, but, will attempt to break it and, is driven by quality
Test cases • Describe how to test a system/module/function • Description must identify • system state before executing the test • function to be tested • parameter values for the test • expected outcome of the test Some automation should be possible after defining them!
requirements output input events Black box vs. white box testing
White box testing …our goal is to ensure that all statements and conditions have been executed at least once...
White box testing:Why cover all paths? • logic errors and incorrect assumptions are inversely proportional to a path’s execution probability • we often believe that a path is not likely to be executed; in fact, reality is often counter intuitive • typographical errors are random; it’s likely that untested paths will contain some
If-then-else loop < 20x Guaranteed cover:Exhaustive testing But: There are 520=1014 (approx.) possible paths!
loop < = 20x Better:Selective testing a selected path
Path coverage testing 1) Derive a logical complexity measure 2) Use it to define a basis set of execution paths First, we compute the cyclomatic complexity V(G): number of transitions - number of nodes +2 In this case, V (G) = 4 V(G) provides an upper bound of tests that must be executed to guarantee coverage of all program statements
Path coverage set • Cyclomatic complexity defines the number of independent paths in the basis set • Path coverage set = set of paths that will execute all statements and all conditions in a program at least once • Goal: Define test cases for basis set • Path coverage set is not unique!
1 2 4 3 5 6 7 8 Path coverage testing Next, we derive the independent paths: Since V(G) = 4, there are four paths Path 1: 1,2,3,6,7,8 Path 2: 1,2,3,5,7,8 Path 3: 1,2,4,7,8 Path 4: 1,2,4,7,2,4…7,8 Finally, we derive test cases to exercise these paths, i.e. choose inputs that lead to traversing the paths
Documenting test cases • Name • Number • Description of system state before running the test case • Values for the inputs • Expected outputs • Short description (if needed)
Path coverage testing - remarks • you don’t need a flow chart, but the picture will help when you trace program paths • each connection between boxes counts as 1 transition • path coverage testing should be applied to critical modules Connects four boxes counts as three transitions
Black box testing requirements output input events
Categories of errors in black box testing • incorrect or missing functions • interface errors • errors in data structures or external database access • performance errors • initialization and termination errors
Example abs(integer x)Return x if x >= 0Return -x if x<0 • The concrete value of x does not matter! Basis for Equivalence Testing
Loops • Cornerstone of every program • Loops can lead to non-terminating programs
Loop testing simple loop nested loops concatenated loops unstructured loops
Loop testing: simple loops Minimum conditions - simple loops 1. skip the loop entirely 2. only one pass through the loop 3. two passes through the loop 4. m passes through the loop m < n 5. (n-1), n, and (n+1) passes through the loop where n is the maximum number of allowable passes
Nested loops • Just extending simple loop testing: number of tests explodes • Reduce the number of tests: • start at the innermost loop; set all other loops to minimum values • conduct simple loop test; add out of range or excluded values • work outwards while keeping inner nested loops to typical values • continue until all loops have been tested
Equivalence class testing Equivalence partitioning mouse picks on menu output format requests user queries responses to prompts numerical data command key input Partitioning is based on input conditions
Equivalence classes (1) • Valid data • user supplied commands • responses to system prompts • file names • computational dataphysical parametersbounding valuesinitiation values • output data formatting commands • responses to error messages • graphical data (e.g., mouse picks)
Equivalence classes (2) • Invalid data • data outside bounds of the program • physically impossible data • proper value supplied in wrong place
Defining equivalence classes • Input condition is a range: one valid and two invalid classes are defined • Input condition requires specific value: one valid and two invalid classes are defined • Input condition is boolean: one valid and one invalid class are defined Then define one test case for each equivalence class
Automating software testing • Manual software testing is time consuming • Software testing has to be repeated after every change (regression testing) • Write test drivers that can run automatically and produce a test report
Testing OO software: general remarks • Based on UML specifications • Use cases • Class diagrams • State transition diagrams • … • Problem: Effort focus on requirements not comprehensive quality?
Scenario based testing • Concentrates on (functional) requirements • Based on • use cases • corresponding sequence diagrams
Test Requirements • Every use case • Every fully expanded extension (<<extend>>) combination • Every fully expanded uses (<<uses>>) combination • Tests normal as well as exceptional behavior
Test Procedure (1) • Establish testing budget • Rank Use Cases (& variants) according to • Relative frequencies • Criticality • Allocate #test cases to each use case (and possibly variants) • Develop test cases for scenarios
Testing a use case/scenarios (1) • A scenario is a path through a sequence diagram • There are many different scenarios associated with a sequence diagram!
What can be wrong? • Incorrect or missing output • Missing function/feature in an object • Incorrect parameter values boundary value analysis • Correct message - wrong object • Incorrect message - right object • Incorrect object state • Message sent to destroyed object • Incorrect exception thrown • Incorrect exception handling • Incorrect assumption about receiver’s class • Class casts
Testing a use case/scenarios (2) • All paths in sequence diagram should be executed • Focus on messages from the actor/UI to the system • If possible: check “internal” objects • Extract control flow information from a sequence diagram • Test branches and loops • Test exceptions • Consider state
<4] Example: Establish Session
Example (cont.) • Several checks are performed • Is the card an ATM card? • Is the card stolen? • Has the customer a valid bank account? • Has the customer a valid PIN? • Three chances to enter the PIN • Service charge if from different bank
Test Procedure (2) • Translate the sequence diagram into a flow graph • Each message or group of consecutive messages becomes a segment (box). • A conditional action (branch, iteration) ends a segment • Each bracketed (loop) condition becomes a decision (hexagon)
Remarks • White-box testing can be applied to flow graph • Control flow graph may reveal • ambiguities and omissions in the sequence diagram • Ambiguities either reveal faults or a behavior to be interpreted by the coder
Path conditions • Input and object state need to satisfy the path conditions • Identify predicates on each path, work from first predicate and identify required input and state variable values • Do the same for the next path conditions until the last one • Some paths may not be feasible