Beruflich Dokumente
Kultur Dokumente
Peter Bunus Department of Computer and Information Science Linkping University, Sweden peter.bunus@liu.se
System Design
(Architecture, High-level Design)
System Testing
(Integration testing of modules)
Module Design
(Program Design, Detailed Design)
Module Testing
(Integration testing of units)
Implementation
of Units (classes, procedures, functions)
Unit testing
! ! ! ! ! ! !
Integration Testing System Testing Acceptance Testing Regression Testing Object-Oriented and other type of Testing Testing Paradigm Industry applications
Course Literature
Focus only on Software test design, not related subjects such as test planning, test management, test team development, etc. ! A Practitioners Guide to Software Test Design by Lee Copeland
Main course literature Available online as an electronic book via the university library
! Other literature:
The Art of Software testing by Glenford J. Myers Software Testing, A Craftsmans Approach by Paul C. Jorgensen Introduction to Software Testing by Paul Amman and Jeff Offutt
For more software testing book recommendations check the Pinterest board of the course http://pinterest.com/tddd04/
Examination
! The course has the following examination items:
Written exam (U, 3, 4, 5), 4 ECTS The exam consist of theoretical and practical exercises For examples of past exams please consult the course webpage Laboratory work (U, G), 2 ECTS for the lab series. Registration for the laboratories is done via webreg. Deadline for signing-up for the labs is on March 13. Please direct all the lab-related questions to your laboratory teaching assistant Usman Dastgeer Respect the deadlines. After the submission deadline for the laboratories we do not have the possibility to correct and grade your labs anymore.
TDDD04 Crew
! Peter Bunus
Associate Professor at Department of Computer and Information Science, Linkping University Examiner and Course Responsible
! Khristian Sandahl
Professor in Software Engineering at Department of Computer and Information Science, Linkping University Invited Lecturer
! Usman Dastgeer
Teaching assistant. Responsible with the laboratories.
Social Networking
If you are twittering about the course please use the following hash tag #tddd04
Part I
Introduction, Testing Process
Part II
Unit Testing:
10
On a sheet of paper, write a set of test cases (i.e., specific sets of data) that you feel would adequately test this program.
Test case a b c Expected output __________________________________________________________________ 1 3 3 4 isosceles (likbent) 2 ? ? ? ?
11
Evaluation of set of test cases (one point for each yes answer)
1. 2. 3. 4. 5. 6. 7. 8. Do you have a test case that represents a valid scalene triangle? (note that test cases such as 1,2,3 and 2,5,10 do not warrant a yes answer, because there does not exist a triangle having such sides.) Do you have a test case that represents a valid equilateral triangle? Do you have a test case that represents a valid isosceles triangle? (2,2,4 would not be counted) Do you have at least three test cases that represent valid isosceles triangles such that you have tried all three permutations of two equal sides (e.g., 3,3,4; 3,4,3; and 4,3,3)? Do you have a test case in which one side has a zero value? Do you have a test case in which one side has a negative value? Do you have a test case with three integers greater than zero such that the sum of two of the numbers is equal to the third? (That is, if the program said that 1,2,3 represents a scalene triangle, it would contain a bug.) Do you have at least three test cases in category 7 such that you have tried all three permutations where the length of one side is equal to the sum of the lengths of the other two sides (e.g., 1,2,3; 1,3,2; and 3,1,2)? Do you have a test case with three integers greater than zero such that the sum of two of the numbers is less than the third? (e.g., 1,2,4 or 12,15,30) Do you have at least three test cases in category 9 such that you have tried all three permutations (e.g., 1,2,4; 1,4,2; and 4,1,2)? Do you have a test case in which all sides are 0 (i.e., 0,0,0)? Do you have at least one test case specifying noninteger values? Do you have at least one test case specifying the wrong number of values (e.g., two rather than three, integers)? For each test case, did you specify the expected output from the program in addition to the input values.
12
Triangle Program
public int triangleType(int[] sides) { if (sides.length != 3) { // Illegal nr of args throw new IllegalArgumentException("Not a triangle."); } int[] s = (int[]) sides.clone(); if (s[0] > s[1]) { swap(s, 0, 1);} // Arranging the sides if (s[0] > s[2]) { swap(s, 0, 2);} // in increasing order if (s[1] > s[2]) { swap(s, 1, 2);} if (s[0] <= 0 || s[2] - s[0] >= s[1]) { throw new IllegalArgumentException("Not a triangle."); } if (s[0] == s[2]) { return TriangleType.EQUILATERAL; } else if (s[0] == s[1] || s[1] == s[2]) { return TriangleType.ISOSCELES;} else { return TriangleType.SCALENE;} } private void swap(int[] s, int i, int j) { int tmp = s[i]; s[i] = s[j]; s[j] = tmp; }
13
The program accepts three integers, a, b, and c as input. The three values are interpreted as representing the lengths of sides of a triangle. The integers a, b, and c must satisfy the following triangle property (the sum of any pair of sides must be greater than the third side).
a<b+c
14
Intended use!!
15
Goal: develop software to meet its intended use! But: human beings make mistake!
bridge
automobile
television
word processor
Product of any engineering activity must be verified against its requirements throughout its development.
16
! Verifying bridge = verifying design, construction, process, ! Software must be verified in much the same spirit. In this lecture, however, we shall learn that verifying software is perhaps more difficult than verifying other engineering products. We shall try to clarify why this is so.
17
Customer
Developer
Code = System
TDDD04 Software Testing
Design Specification
18
Can lead to
Can lead to
Failure
19
Basic Definitions
The terminology here is taken from standards developed by the institute of Electronics and Electrical Engineers (IEEE) computer Society. ! Error: people make errors. A good synonym is mistake. When people make mistakes while coding, we call these mistakes bugs. Errors tend to propagate; a requirements error may be magnified during design and amplified still more during coding. Fault: a fault is the result of an error. It is more precise to say that a fault is the representation of an error, where representation is the mode of expression, such as narrative text, data flow diagrams, hierarchy charts, source code, and so on. Defect is a good synonym for fault, as is bug. Faults can be elusive. When a designer makes an error of omission, the resulting fault is that something is missing that should be present in the representation. We might speak of faults of commission and faults of omission. A fault of commission occurs when we enter something into a representation that is incorrect. Faults of omission occur when we fail to enter correct information. Of these two types, faults of omission are more difficult to detect and resolve. Failure: a failure occurs when a fault executes. Two subtleties arise here: one is that failures only occur in an executable representation, which is usually taken to be source code, or more precisely, loaded object; the second subtlety is that this definition relates failures only to faults of commission. How can we deal with failures that correspond to faults of omission?
20
Types of Faults
! ! ! ! ! ! ! ! ! ! Algorithmic: division by zero Computation & Precision: order of op Documentation: doc - code Stress/Overload: data-str size ( dimensions of tables, size of buffers) Capacity/Boundary: x devices, y parallel tasks, z interrupts Timing/Coordination: real-time systems Throughout/Performance: speed in req. Recovery: power failure Hardware & System Software: modem Standards & Procedure: organizational standard; difficult for programmers to follow each other.
21
1. 2. 3. 4. 5. 6. 7. 8.
Misspelled word Misleading or redundant information Truncated names, bill for $0.00 Some transaction(s) not processed Lose a transaction Incorrect transaction execution Frequent very serious errors Database corruption System shutdown Shutdown that spreads to others
22
23
Fault
Design
Error Fault
Coding
Incident
Testing
Fault Classification
24
Program Behaviors
Specification (expected)
Program (observed)
25
Correctness
! ! Impossible to demonstrate. A relative term: Program P is correct with respect to specification S. Bottom Line: do the specification and program meet the customer/ users expectations
26
Specification (expected)
Program (observed)
27
Basic Approaches
Specification Program
28
Black Box
Inputs
Outputs
Function is understood only in terms of it's inputs and outputs, with no knowledge of its implementation.
29
30
Test cases
31
32
Testing level
! Unit testing ! Integration testing ! System testing ! Acceptance testing
33
34
Code = System
Design Specification
35
Unit Testing
36
Component code
Integration test Component code Unit test Tested components Integrated modules
37
Failure?
Output Oracle
38
39
A correct program
A typical program
41
Inspection
(originally introduced by Fagan 1976)
42
Inspection (cont)
some classical programming errors
! Use of un-initialized variables ! Jumps into loops ! Non-terminating loops ! Incompatible assignments ! Array indexes out of bounds ! Off-by-one errors ! Improper storage allocation or de-allocation ! Mismatches between actual and formal parameters in procedure calls
43
Walkthroughs
Walkthrough design, code, chapter of users guide, ! presenter ! coordinator ! secretary ! maintenance oracle ! standards bearer ! user representative
44
Discovery Activity Requirements review Design Review Code Inspection Integration test Acceptance test
Faults found per thousand lines of code 2.5 5.0 10.0 3.0 2.0
Jons, S et al, Developing international user information. Bedford, MA: Digital Press, 1991.
45
Experiments
! 82% of faults discovered during design & code inspection (Fagan). ! 93% of all faults in a 6000-lines application were found by inspections (Ackerman, et al 1986).
! 85% of all faults removed by inspections from examining history of 10 million lines of code (Jones 1977).
46
47
Black-box Testing
1. 2. 3. 4. 5. 6. 7. 8. Exhaustive testing Equivalence class testing (Equivalence Partitioning) (chapter 3) Boundary value analysis (chapter 4) Decision table testing (chapter 5) Pairwise testing (chapter 6) State-Transition testing (chapter 7) Domain analysis testing (chapter 8) Use case testing (chapter 9)
48
input
output
49
50
Exhaustive testing
! Definition: testing with every member of the input value space. ! Input value space: the set of all possible input values to the program.
int icrement(int a) { }
If one test will take 1 ms how much time it will take to test exhaustively function above? No of possible inputs Time to test
From 2,147,483,648 to 2,147,483,647, from (231) to 231 1= 232 1 possible inputs 232 1 ms = (232 1)/1000 sec = 1.6 months
52
53
x < ? x > ?
x
1
50
50
54
Valid ECs: ! M1 = {month: 1 =< month =< 12} ! D1 = {day: 1 =< day =< 31} ! Y1 = {year: 1812 =< year =< 1012} Invalid ECs: ! M2 = {month: month < 1} ! M2 = {month: month > 12} ! D2 = {day: day < 1} !
55
Guidelines
1. 2. If an input condition specifies a range of values; identify one valid EC and two invalid EC. If an input condition specifies the number (e.g., one through 6 owners can be listed for the automobile); identify one valid EC and two invalid EC (- no owners; - more than 6 owners). If an input condition specifies a set of input values and there is reason to believe that each is handled differently by the program; identify a valid EC for each and one invalid EC. If an input condition specifies a must be situation (e.g., first character of the identifier must be a letter); identify one valid EC (it is a letter) and one invalid EC (it is not a letter) If there is any reason to believe that elements in an EC are not handled in an identical manner by the program, split the equivalence class into smaller equivalence classes.
3.
4.
5.
56
57
58
Equivalence partitioning
Invalid inputs
Valid inputs
outputs
59
Example
Specification: the program accepts four to eight inputs which are 5 digit integers greater than 10000.
Input values
Less than 10000 Between 10000 and 99999 More than 99999
60
61
62
63
99999 100000
64
Boundary Value Analysis Test Cases for Triangle program (upper bound 200)
Test case
1 2 3 4
a
100 100 100 100
b
100 100 100 100
c
1 2 199 200
Expected output
isosceles (likbent) isosceles isosceles not a triangle
______________________________________________________________________________________________
65
66
67
68