Software Testing Part II Functional Testing Aditya P

  • Slides: 126
Download presentation
Software Testing: Part II: Functional Testing Aditya P. Mathur Purdue University July 20 -24,

Software Testing: Part II: Functional Testing Aditya P. Mathur Purdue University July 20 -24, 1998 @ Raytheon Technical Services Company Indianapolis. Graduate Assistants: Last update: July 19, 1998 Functional testing Joao Cangussu Sudipto Ghosh Priya Govindrajan

Course Organization Part I: Part III: Part IV: Preliminaries Functional Testing Test Assessment Special

Course Organization Part I: Part III: Part IV: Preliminaries Functional Testing Test Assessment Special Topics Functional testing 2

Part II: Functional testing 4 Learning objectives– What is functional testing? – How to

Part II: Functional testing 4 Learning objectives– What is functional testing? – How to perform functional testing? • What are clues, test requirements, and test specifications? • How to generate test inputs? – What are equivalence partitioning, boundary value testing, domain testing, state testing, and decision table testing? Functional testing 3

What is functional testing? 4 When test inputs are generated using program specifications, we

What is functional testing? 4 When test inputs are generated using program specifications, we say that we are doing functional testing. 4 Functional testing tests how well a program meets the functionality requirements. Functional testing 4

The methodology 4 The derivation of test inputs is based on program specifications. 4

The methodology 4 The derivation of test inputs is based on program specifications. 4 Clues are obtained from the specifications. 4 Clues lead to test requirements. 4 Test requirements lead to test specifications. 4 Test specifications are then used to actually execute the program under test. Functional testing 5

Test methodology Specifications Clues Expected behavior Test requirements Oracle Test specifications Until specs. Exhausted.

Test methodology Specifications Clues Expected behavior Test requirements Oracle Test specifications Until specs. Exhausted. Test driver Actual behavior Program Functional testing Program output is correct or Program has failed; make a note and proceed with testing or get into the debug mode. 6

Specifications 4 Inputs and tasks: – Given inputs – Perform tasks Functional testing 7

Specifications 4 Inputs and tasks: – Given inputs – Perform tasks Functional testing 7

Specifications-continued 4 Input properties – Input – must satisfy 4 Function f is a

Specifications-continued 4 Input properties – Input – must satisfy 4 Function f is a pre-condition on input Functional testing 8

Specifications-continued 4 Two types of pre-conditions are considered: – Validated: those that are required

Specifications-continued 4 Two types of pre-conditions are considered: – Validated: those that are required to be validated by the program under test and an error action is required to be performed if the condition is not true. – Assumed: those that are assumed to be true and not checked by the program under test. Functional testing 9

Specification: example 4 For the sort program: – Inputs are: • N • pointer

Specification: example 4 For the sort program: – Inputs are: • N • pointer to a sequence of length N • pointer to an area in memory where the output sequence is to be placed. Functional testing 10

Specification: example. . continued – Tasks to be performed: • Sort the sequence in

Specification: example. . continued – Tasks to be performed: • Sort the sequence in ascending order • Return the sorted sequence in an area provided. • Return 1 if sorting is successful, -1 otherwise. Functional testing 11

Preconditions for sort 4 Validated: – N>0 – On failure return -1; sorting considered

Preconditions for sort 4 Validated: – N>0 – On failure return -1; sorting considered unsuccessful. 4 Assumed: – The input sequence contains N integers. – The output area has space for at least N integers. Functional testing 12

Deriving pre-conditions 4 Pre-conditions result from properties of inputs. 4 Example: – alpha_sequence(name) alpha_sequence

Deriving pre-conditions 4 Pre-conditions result from properties of inputs. 4 Example: – alpha_sequence(name) alpha_sequence is the string obtained from name by removing all characters other then AZ, and a-z. Thus, if name is “A 12 C” then alpha_name is “AC”. Functional testing 13

Deriving pre-conditions-continued 4 This leads to the following pre-condition: – Validated: the string alpha_sequence(name)

Deriving pre-conditions-continued 4 This leads to the following pre-condition: – Validated: the string alpha_sequence(name) is shorter than name. – On failure: print “invalid name”. 4 This property could also lead to the pre- condition: – Assumed: the string alpha_ sequence(name) is shorter than name. Functional testing 14

Post-conditions 4 A post-condition specifies a property of the output of a program. 4

Post-conditions 4 A post-condition specifies a property of the output of a program. 4 The general format of a post-condition is: – if condition then effect-1 {else effect-2} 4 Example: – For the sort program a post-condition is: • if N>0 then {the output sequence has the same elements as in the input sequence and in ascending order. } Functional testing 15

Post-condition-continued – This could be stated more formally as: • if N>0 then {

Post-condition-continued – This could be stated more formally as: • if N>0 then { and each is a member of the input sequence and sort returns 1. } else { the output sequence is undefined and sort returns -1. } Functional testing 16

Post-condition-continued 4 Another example: – if (A=B) and (B=C) then return “equilateral”; 4 Can

Post-condition-continued 4 Another example: – if (A=B) and (B=C) then return “equilateral”; 4 Can you complete the above post-condition for a program that is required to classify a triangle given the length of three sides? 4 Convention: We will not nest if-then-else statements while specifying a post-condition. Functional testing 17

Incompleteness of specifications 4 Specifications may be incomplete or ambiguous. 4 Example post-condition: if

Incompleteness of specifications 4 Specifications may be incomplete or ambiguous. 4 Example post-condition: if user places cursor on the name field then read a string – This post-condition does not specify any limit on the length of the input string hence is incomplete. Functional testing 18

Ambiguous specifications 4 It also does not make it clear as to – whether

Ambiguous specifications 4 It also does not make it clear as to – whether a string should be input only after the user has placed the cursor on the name field and clicked the mouse or simply placed the cursor on the name field. and hence is ambiguous. Functional testing 19

Clues: summary 4 Clues are: – Pre-conditions – Post-conditions – Variables, e. g. A

Clues: summary 4 Clues are: – Pre-conditions – Post-conditions – Variables, e. g. A is a length implying thereby that its value cannot be negative. – Operations, e. g. “search a list of names” or “find the average of total scores” – Definitions, e. g. “filename(name) is a name is no spaces. ” Functional testing 20

Clues-continued 4 Ideally variables, operations and definitions should be a part of at least

Clues-continued 4 Ideally variables, operations and definitions should be a part of at least one pre- or postcondition. 4 However, this may not be the case as specifications are not always written formally. 4 Hence look out for variables, operations, and definitions within a specification! Functional testing 21

Test requirements 4 A test requirement is a description of how to test the

Test requirements 4 A test requirement is a description of how to test the program that is under test. 4 Here is a sample test requirement for a program that classifies a triangle given the length of three sides. – A, B, C are non-zero and positive. – One of A, B, C is negative; error condition. – One of A, B, C is zero; error condition. Functional testing 22

Test requirements-derivation 4 Test requirements are derived from clues. 4 For example, consider the

Test requirements-derivation 4 Test requirements are derived from clues. 4 For example, consider the following pre- conditions (clues): • Assumed: A, B, and C are lengths • Validated: A>0, B>0, C>0 4 These pre-conditions on A, B, and C lead to the test requirement given above. Functional testing 23

Test requirements-derivation 4 Note that we have clumped pre-condition for each input variable into

Test requirements-derivation 4 Note that we have clumped pre-condition for each input variable into one condition. This is being done only for inconvenience. 4 It is recommended that pre-conditions be separated for each variable. Functional testing 24

Test requirements-derivation 4 Note also that each validated pre-condition results in at least two

Test requirements-derivation 4 Note also that each validated pre-condition results in at least two requirements: one for the validated part and the other for the failure part. 4 In our example above we did not list all requirements. For example, we are content with testing “one of A, B, C is negative; error condition. ” Functional testing 25

Test requirements-derivation 4 Post-conditions also lead to test requirements. 4 For example, the partial

Test requirements-derivation 4 Post-conditions also lead to test requirements. 4 For example, the partial post-condition: • if (A=B) and (B=C) then return “equilateral” leads to the following test requirement: • A=B and B=C. Functional testing 26

Compound validated pre-conditions 4 Compound pre-conditions are ones that use the and or or

Compound validated pre-conditions 4 Compound pre-conditions are ones that use the and or or connectors. 4 Examples: validated compound preconditions: – Pre-condition: A and B – Pre-condition: user places the mouse over the name field and clicks it. Functional testing 27

Compound validated pre-conditions 4 The first of the above pre-conditions leads to four requirements:

Compound validated pre-conditions 4 The first of the above pre-conditions leads to four requirements: • • A true, B true A false, B true A true, B false A false, B false (This is the validated part) (This and the rest are failures) 4 You may work out the requirements for compound pre-condition with the or connector. Functional testing 28

Compound validated pre-conditions 4 Compound validated pre-conditions could become quite complex. 4 Example: (A

Compound validated pre-conditions 4 Compound validated pre-conditions could become quite complex. 4 Example: (A and (B or C)) 4 Brute force method will lead to 8 test requirements. Functional testing 29

Compound validated pre-conditions 4 In general this will lead to too many test requirements.

Compound validated pre-conditions 4 In general this will lead to too many test requirements. 4 We can prune them by leaving out those requirements that are unlikely to reveal a program error. 4 For example, consider the validated precondition: A or B. Functional testing 30

Pruning test requirements 4 There are four possible test requirements: • • A true,

Pruning test requirements 4 There are four possible test requirements: • • A true, B true A false, B true A true, B false A false, B false 4 Consider a correct C implementation: if (!(A || B)) exit_with_error(“Error: A is %d, B is %d”, A, B); else. . {/* the validated code comes here. */} Functional testing 31

Possible errors 4 Programmer forgets to check for one of the two cases resulting

Possible errors 4 Programmer forgets to check for one of the two cases resulting in the code: • if (!A) exit_with_error(“Error: A is %d, B is %d”, A, B); or • if (!B) exit_with_error(“Error: A is %d, B is %d”, A, B); Functional testing 32

Possible errors-continued 4 Or use a wrong logical operator as in: if (!(A &&

Possible errors-continued 4 Or use a wrong logical operator as in: if (!(A && B)) exit_with_error(“Error: A is %d, B is %d”, A, B); 4 Let us analyze how the four different tests will perform in each of the four implementations: one correct, and three incorrect ones. Functional testing 33

Truth table: or condition Inputs Correct implementation Incorrect implementations A B !(A || B)

Truth table: or condition Inputs Correct implementation Incorrect implementations A B !(A || B) !(A&&B) !A !B T F F T F T F T T T F F T T F T F Notice this one: will it help find any of the three possible errors? Functional testing 34

Truth table analysis Case 1: – A test input with A=true and B=false will

Truth table analysis Case 1: – A test input with A=true and B=false will cause the correct program to evaluate the condition to false. – The two incorrect implementations, !(A&&B) and (!B) will evaluate the condition to true. Functional testing 35

Truth table analysis-continued – Both incorrect implementations will print the error message. – The

Truth table analysis-continued – Both incorrect implementations will print the error message. – The oracle will observe that the correct and the incorrect implementations behave differently. – It will therefore announce failure for each incorrect implementation thereby pointing to an error. End of Case 1. Functional testing 36

Truth table analysis-continued Case 2: – Test input A=false and B=true will reveal the

Truth table analysis-continued Case 2: – Test input A=false and B=true will reveal the error in the two incorrect implementations, !(A&&B) and (!A). Case 3: – Test input A=false and B=false might find a fault in then branch of the if condition. Functional testing 37

Truth table analysis-continued Case 4: – Test input A=true and B=true might find a

Truth table analysis-continued Case 4: – Test input A=true and B=true might find a fault in the else branch of the if condition. 4 Thus, all four test inputs are likely to be useful. Functional testing 38

Truth table analysis-continued 4 However, if we were to check for the correct implementation

Truth table analysis-continued 4 However, if we were to check for the correct implementation of the condition A or B, then only the first two inputs are necessary. 4 In this example, reducing the number of test specifications from 4 to 2 does not lead to any significant savings. When will the savings be significant? Functional testing 39

Assumed pre-conditions 4 Each assumed pre-condition is likely to result in a test requirement.

Assumed pre-conditions 4 Each assumed pre-condition is likely to result in a test requirement. 4 Example: – Assumed: MODE is “on ground” or “flying” – This leads to two requirements: • MODE is “on ground” , MODE is not “flying” • MODE is not “on ground” , MODE is “flying” Functional testing 40

Assumed pre-conditions – These can be simplified to: • MODE is “on ground” •

Assumed pre-conditions – These can be simplified to: • MODE is “on ground” • MODE is “flying” Functional testing 41

Clues from code? 4 Yes, clues can also be derived by scanning the code.

Clues from code? 4 Yes, clues can also be derived by scanning the code. 4 However, such clues might be redundant and incomplete if coverage measurement and use is planned. 4 In the absence of coverage measurement, it is a good idea to scan the code and find clues. Functional testing 42

Clues from code-continued 4 Examine internal variables. These may lead to new test requirements.

Clues from code-continued 4 Examine internal variables. These may lead to new test requirements. 4 Example: Suppose that variable length is input and denotes the length of an array. In the code we find: int last_index=length+1; This leads to the test requirements: Functional testing 43

Clues from code-continued • an array of length zero • array of length 1

Clues from code-continued • an array of length zero • array of length 1 • array with more than one element – Later we will see how these clues and requirements might be derived, with certainty, using boundary-value analysis. 4 Another example: Consider the sort program for which we have seen the specifications. Functional testing 44

Clues from code-continued 4 The specifications do not indicate what algorithm is to be

Clues from code-continued 4 The specifications do not indicate what algorithm is to be used for sorting the input array. 4 A programmer might decide to use different algorithms for different array sizes. When scanning the code we may see: • if (scan<min_length) simple_sort(); else quicksort(); Functional testing 45

Clues from code-continued 4 Variable size and the check against min_length give us a

Clues from code-continued 4 Variable size and the check against min_length give us a clue for new test requirements. These are: – size is equal to or greater than min_length 4 Later we will see how this clue and requirements might be derived, with certainty, using branch coverage. Functional testing 46

Test requirements checklist 4 Obtaining clues and deriving test requirements can become a tedious

Test requirements checklist 4 Obtaining clues and deriving test requirements can become a tedious task. 4 To keep it from overwhelming us it is a good idea to make a checklist of clues. 4 This checklist is then transformed into a checklist of test requirements by going through each clue and deriving test requirements from it. Functional testing 47

Test specifications 4 A test requirements indicates “how” to test a program. But it

Test specifications 4 A test requirements indicates “how” to test a program. But it does not provide exact values of inputs. 4 A test requirement is used to derive test specification, which is the exact specification of values of input and environment variables. Functional testing 48

Test specifications-continued 4 There may not be a one-to-one correspondence between test requirements and

Test specifications-continued 4 There may not be a one-to-one correspondence between test requirements and test specifications. 4 A test requirement checklist might contain 50 entries. These might result in only 22 test specifications. 4 The fewer the tests the better but only if these tests are of good quality! Functional testing 49

Test specifications-continued 4 We will discuss test quality when discussing test assessment. 4 A

Test specifications-continued 4 We will discuss test quality when discussing test assessment. 4 A test specification looks like this: – Test 2: • global variable all_files is initially false. • next_record is set to 1. – Upon return expect: • all_files to be true • next_record is last_record+1 Functional testing 50

Test specifications-continued 4 Notice the format of a test specification: – Each test is

Test specifications-continued 4 Notice the format of a test specification: – Each test is given a number which serves as its identifier. – There is a set of input values. – There is a set of expected values upon return from execution. Any side effects on files or networks must also be specified here. In essence, all observable effects must be specified in the “Expect” part of a test specification. Functional testing 51

Test specifications-continued – Any side effects on files or networks must also be specified.

Test specifications-continued – Any side effects on files or networks must also be specified. In essence, all observable effects must be specified in the “Expect” part of a test specification. – Similarly, values of all input variables, global or otherwise, must also be specified. Functional testing 52

Test requirements to specifications 4 The test requirements checklist guides the process of deriving

Test requirements to specifications 4 The test requirements checklist guides the process of deriving test specifications. 4 Initially all entries in the checklist are unmarked or set to 0. 4 Each time a test is generated from a requirement it is marked or the count incremented by 1. Functional testing 53

Test requirements to specifications 4 Thus, at any point in time, one could assess

Test requirements to specifications 4 Thus, at any point in time, one could assess the progress made towards the generation of test specifications. 4 One could also determine how many tests have been generated using any test requirement. Functional testing 54

Test requirements to specifications 4 Once a test requirement has been marked or its

Test requirements to specifications 4 Once a test requirement has been marked or its count is more than 0 we say that it has been satisfied. 4 Some rules of thumb to use while designing tests: – Try to satisfy multiple requirements using only one test. – Satisfy all test requirements. Functional testing 55

Test requirements to specifications – Avoid reuse of same values of a variable in

Test requirements to specifications – Avoid reuse of same values of a variable in different tests. Generating new tests by varying an existing one is likely to lead to tests that test the same part of the code as the previous one. In testing, variety helps! 4 Though we try to combine several test requirements to generate one test case, this is not advisable when considering error conditions. Functional testing 56

Test requirements to specifications 4 For example, consider the following: – speed_dial, an interval

Test requirements to specifications 4 For example, consider the following: – speed_dial, an interval • speed_dial<0 , error • speed_dial>120, error – zones, an interval • zones <5, error • zones>10, error Functional testing 57

Test requirements to specifications – One test specification obtained by combining the two requirements

Test requirements to specifications – One test specification obtained by combining the two requirements above is: • speed_dial=-1 • zone=3 4 Now, if the code to handle these error conditions is: Functional testing 58

Test requirements to specifications if (speed_dial<0 || speed_dial>120) error_exit(“Incorrect speed_dial”); if (zone<6 ||zone>10) error_exit(“Incorrect

Test requirements to specifications if (speed_dial<0 || speed_dial>120) error_exit(“Incorrect speed_dial”); if (zone<6 ||zone>10) error_exit(“Incorrect zone”); – For our test, the program will exit before it reaches the second if statement. Thus, it will miss detecting the error in coding the test for zone. Functional testing 59

Test requirements to specifications 4 Also, do not assume an error test to satisfy

Test requirements to specifications 4 Also, do not assume an error test to satisfy any other test requirement. 4 Example: – Consider the function: • myfunction(int X, int Y); – A test for the erroneous value of X might not test the code that uses Y. Functional testing 60

Test requirements to specifications 4 Test specifications must not mention internal variables. Remember, a

Test requirements to specifications 4 Test specifications must not mention internal variables. Remember, a test specification aids in setting input variables to suitable values before the test begins. Values of internal variables are computed during program execution. 4 However, there are exceptions to the above rule. Can you think of one? Functional testing 61

A peek into today’s laboratory 4 The laboratory is based on the example given

A peek into today’s laboratory 4 The laboratory is based on the example given in your text by Marick. 4 The example is based on a C program sreadhex. 4 Given the specifications and code of sreadhex you will be required to find clues, develop test requirements, and test specifications. Functional testing 62

A peek into today’s laboratory 4 You will then test sreadhex using tests derived

A peek into today’s laboratory 4 You will then test sreadhex using tests derived by you. 4 To test sreadhex you will write a test driver. 4 More details will be provided during the laboratory session. 4 Let us examine sreadhex! Functional testing 63

The sreadhex program 4 Inputs: – A string of characters (s). • The characters

The sreadhex program 4 Inputs: – A string of characters (s). • The characters in the string represent hexadecimal digits. s is null terminated. – Maximum number of bytes (rlen) in the output array (str). – A pointer to an integer (odd-digit). Functional testing 64

The sreadhex program 4 Outputs: – A packed array of bytes (str) containing a

The sreadhex program 4 Outputs: – A packed array of bytes (str) containing a maximum of rlen bytes. • The hexadecimal characters in the input string are converted to their 4 -bit binary equivalent. Two successive hexadecimal digits are packed into one byte of str. – if the number of digits in str is odd, then the 4 bit value of the last hexadecimal digit in s is placed in odd-digit else odd-digit is set to -1. Functional testing 65

The sreadhex program – The number of bytes filled in str is returned in

The sreadhex program – The number of bytes filled in str is returned in nread. – Any non-hexadecimal characters in s are ignored. – sreadhex returns 1 if all hexadecimal characters filled in the output array, 0 if not; -1 if there was an error. Functional testing 66

The sreadhex program 4 Examples: – Input: • s=“ 4 EDIT” • odd_digit=-1 •

The sreadhex program 4 Examples: – Input: • s=“ 4 EDIT” • odd_digit=-1 • rlen=2 “T” and “I” ignored – Output: • str byte 1: • odd_digit: • nread: 01001110 1101 1 Functional testing Odd digit “D” 67

The sreadhex program – Input: • s=“ 3 A” • odd_digit=5 • rlen=2 Odd

The sreadhex program – Input: • s=“ 3 A” • odd_digit=5 • rlen=2 Odd digit from previous call – Output: • str byte 1: • odd_digit: • nread: 01010011 1010 1 Functional testing Input odd_digit placed in the first byte. 68

The sreadhex program – Input: • s=“ 1 F” • odd_digit=-1 • rlen=2 –

The sreadhex program – Input: • s=“ 1 F” • odd_digit=-1 • rlen=2 – Output: • str byte 1: • odd_digit: • nread: 00011111 -1 1 Functional testing 69

The sreadhex program – Input: • s=“ 1 F 2 A 3” • odd_digit=-1

The sreadhex program – Input: • s=“ 1 F 2 A 3” • odd_digit=-1 • rlen=2 – Output: • • str byte 1: str byte 2: odd_digit: nread: 00011111 00101010 -1 2 Functional testing “ 3” ignored as it is the fifth digit whereas only 4 are allowed in str. 70

Sample pre- and post- conditions 4 Pre-conditions: – Assumed: str is a non-null pointer

Sample pre- and post- conditions 4 Pre-conditions: – Assumed: str is a non-null pointer to an array that can hold rlen bytes. – Validated: rlen is not 0; on failure *nread is 0 and return value is 0. 4 Post-conditions: – An even number of digits and not enough to fill str; use all of them, return value is 1. Functional testing 71

Sample pre- and post- conditions – An odd number of digits and not enough

Sample pre- and post- conditions – An odd number of digits and not enough to fill str; use all of them, set odd-digit to the value of the last hexadecimal digit in str, return 1. – More than enough digits to fill str, ignore excess, return 0. Functional testing 72

Sample definitions 4 START: • Location in str where the value of the first

Sample definitions 4 START: • Location in str where the value of the first hexadecimal character in s is placed. • if (*odd-digit = = -1) then START is 0 else START is 1. Functional testing 73

Using definitions 4 Definitions help formulate and specify pre- and post-conditions. 4 Example: –

Using definitions 4 Definitions help formulate and specify pre- and post-conditions. 4 Example: – if START+NUM_HEX_CHARS>=2*rlen then …… where NUM_HEX_CHARS is the number of hex digits in s. Functional testing 74

Understanding specs and code 4 Look at the specifications of sreadhex: see section 2.

Understanding specs and code 4 Look at the specifications of sreadhex: see section 2. 2 of the text. 4 Look at the code on page 28. 4 Understand the specifications and the code before you begin the laboratory assignments. Functional testing 75

Equivalence partitioning 4 The input domain is usually too large for exhaustive testing. 4

Equivalence partitioning 4 The input domain is usually too large for exhaustive testing. 4 It is therefore partitioned into a finite number of sub-domains for the selection of test inputs. 4 Each sub-domain is known as an equivalence class and serves as a source of at least one test input. Functional testing 76

Equivalence partitioning Input domain partitioned into four sub-domains. 2 1 3 4 Too many

Equivalence partitioning Input domain partitioned into four sub-domains. 2 1 3 4 Too many test inputs. Four test inputs, one selected from each sub-domain. Functional testing 77

How to partition? 4 Inputs to a program provide clues to partitioning. 4 Example

How to partition? 4 Inputs to a program provide clues to partitioning. 4 Example 1: – Suppose that program P takes an input X, X being an integer. – For X<0 the program is required to perform task T 1 and for X>=0 task T 2. Functional testing 78

How to partition? -continued – The input domain is prohibitively large because X can

How to partition? -continued – The input domain is prohibitively large because X can assume a large number of values. – However, we expect P to behave the same way for all X<0. – Similarly, we expect P to perform the same way for all values of X>=0. – We therefore partition the input domain of P into two sub-domains. Functional testing 79

Two sub-domains One test case: X=-3 Equivalence class X<0 X>=0 Another test case: X=-15

Two sub-domains One test case: X=-3 Equivalence class X<0 X>=0 Another test case: X=-15 All test inputs in the X<0 sub-domain are considered equivalent. The assumption is that if one test input in this sub-domain reveals an error in the program, so will the others. This is true of the test inputs in the X>=0 sub-domain also. Functional testing 80

Non-overlapping partitions 4 In the previous example, the two equivalence classes are non-overlapping. In

Non-overlapping partitions 4 In the previous example, the two equivalence classes are non-overlapping. In other words the two sub-domains are disjoint. 4 When the sub-domains are disjoint, it is sufficient to pick one test input from each equivalence class to test the program. Functional testing 81

Non-overlapping partitions 4 An equivalence class is considered covered when at least one test

Non-overlapping partitions 4 An equivalence class is considered covered when at least one test has been selected from it. 4 In partition testing our goal is to cover all equivalence classes. Functional testing 82

Overlapping partitions 4 Example 2: – Suppose that program P takes three integers X,

Overlapping partitions 4 Example 2: – Suppose that program P takes three integers X, Y and Z. It is known that: • X<Y • Z>Y Functional testing 83

Overlapping partitions X<Y, Z<=Y X=2, Y=3, Z=1 X>=Y, Z<=Y X=15, Y=4, Z=1 X<Y, Z>Y

Overlapping partitions X<Y, Z<=Y X=2, Y=3, Z=1 X>=Y, Z<=Y X=15, Y=4, Z=1 X<Y, Z>Y X=3, Y=4, Z=7 X>=Y Z>Y Z<=Y X>=Y, Z>Y X=15, Y=4, Z=7 Functional testing 84

Overlapping partition-test selection 4 In this example, we could select 4 test cases as:

Overlapping partition-test selection 4 In this example, we could select 4 test cases as: – X=4, Y=7, Z=1 – X=4, Y=2, Z=1 – X=1, Y=7, Z=9 – X=1, Y=7, Z=2 satisfies X<Y satisfies X>=Y satisfies Z>Y satisfies Z<=Y 4 Thus, we have one test case from each equivalence class. Functional testing 85

Overlapping partition-test selection 4 However, we may also select only 2 test inputs and

Overlapping partition-test selection 4 However, we may also select only 2 test inputs and satisfy all four equivalence classes: – X=4, Y=7, Z=1 – X=4, Y=2, Z=3 satisfies X<Y and Z<=Y satisfies X>=Y and Z>Y 4 Thus, we have reduced the number of test cases from 4 to 2 while covering each equivalence class. Functional testing 86

Partitioning using non-numeric data 4 In the previous two examples the inputs were integers.

Partitioning using non-numeric data 4 In the previous two examples the inputs were integers. One can derive equivalence classes for other types of data also. 4 Example 3: – Suppose that program P takes one character X and one string Y as inputs. P performs task T 1 for all lower case characters and T 2 for upper case characters. Also, it performs task T 3 for the null string and T 4 for all other strings. Functional testing 87

Partitioning using non-numeric data X: LC, Y: not null X: UC, Y: not null

Partitioning using non-numeric data X: LC, Y: not null X: UC, Y: not null X: LC X: UC X: LC, Y: null Y: not null X: UC, Y: null Functional testing LC: Lower case character UC: Upper case character null: null string. 88

Non-numeric data 4 Once again we have overlapping partitions. 4 We can select only

Non-numeric data 4 Once again we have overlapping partitions. 4 We can select only 2 test inputs to cover all four equivalence classes. These are: – X: lower case, Y: null string – X: upper case, Y: not a null string Functional testing 89

Guidelines for equivalence partitioning 4 Input condition specifies a range: create one for the

Guidelines for equivalence partitioning 4 Input condition specifies a range: create one for the valid case and two for the invalid cases. – e. g. for a<=X<=b the classes are • a<=X<=b (valid case) • X<a and X>b (the invalid cases) Functional testing 90

Guidelines-continued 4 Input condition specifies a value: create one for the valid value and

Guidelines-continued 4 Input condition specifies a value: create one for the valid value and two for incorrect values (below and above the valid value). This may not be possible for certain data types, e. g. for boolean. 4 Input condition specifies a member of a set: create one for the valid value and one for the invalid (not in the set) value. Functional testing 91

Sufficiency of partitions 4 In the previous examples we derived equivalence classes based on

Sufficiency of partitions 4 In the previous examples we derived equivalence classes based on the conditions satisfied by input data. 4 Then we selected just enough tests to cover each partition. 4 Think of the advantages and disadvantages of this approach! Functional testing 92

Boundary value analysis (BVA) 4 Another way to generate test cases is to look

Boundary value analysis (BVA) 4 Another way to generate test cases is to look for boundary values. 4 Suppose a program takes an integer X as input. 4 In the absence of any information, we assume that X=0 is a boundary. Inputs to the program might lie on the boundary or on either side of the boundary. Functional testing 93

BVA: continued 4 This gives us 3 test inputs: • X=0, X=-20, and X=14.

BVA: continued 4 This gives us 3 test inputs: • X=0, X=-20, and X=14. – Note that the values -20 and 14 are on either side of the boundary and are chosen arbitrarily. 4 Notice that using BVA we get 3 equivalence classes. One of these three classes contains only one value (X=0), the other two are large! Functional testing 94

BVA: continued 4 Now suppose that a program takes two integers X and Y

BVA: continued 4 Now suppose that a program takes two integers X and Y and that x 1<=X<=x 2 and y 1<=Y<=y 2. y 2 9 12 4 2 10 11 8 y 1 5 1 14 13 7 x 1 6 3 x 2 Functional testing 95

BVA-continued 4 In this case the four sides of the rectangle represent the boundary.

BVA-continued 4 In this case the four sides of the rectangle represent the boundary. 4 The heuristic for test selection in this case is: – Select one test at each corner (1, 2, 3, 4). – Select one test just outside of each of the four sides of the boundary (5, 6, 7, 8) Functional testing 96

BVA-continued – Select one test just inside of each of the four sides of

BVA-continued – Select one test just inside of each of the four sides of the boundary (10, 11, 12, 13). – Select one test case inside of the bounded region (9). – Select one test case outside of the bounded region (14). 4 How many equivalence classes do we get? Functional testing 97

BVA -continued 4 In the previous examples we considered only numeric data. 4 BVA

BVA -continued 4 In the previous examples we considered only numeric data. 4 BVA can be done on any type of data. 4 For example, suppose that a program takes a string S and an integer X as inputs. The constraints on inputs are: – length(S)<=100 and a<=X<=b 4 Can you derive the test cases using BVA? Functional testing 98

BVA applied to output variables 4 Just as we applied BVA to input data,

BVA applied to output variables 4 Just as we applied BVA to input data, we can apply it to output data. 4 Doing so gives us equivalence classes for the output domain. 4 We then try to find test inputs that will cover each output equivalence class. Functional testing 99

BVA-continued 4 Example: each student to construct one! Functional testing 100

BVA-continued 4 Example: each student to construct one! Functional testing 100

Finite State Machines (FSMs) 4 A state machine is an abstract representation of actions

Finite State Machines (FSMs) 4 A state machine is an abstract representation of actions taken by a program or anything else that functions! 4 It is specified as a quintuple: • A: a finite input alphabet • Q: a finite set of states • q 0: initial state which is a member of Q. Functional testing 101

FSMs-continued • T: state transitions which is a mapping Q x A--> Q •

FSMs-continued • T: state transitions which is a mapping Q x A--> Q • F: A finite set of final states, F is a subset of Q. – Example: Here is a finite state machine that recognizes integers ending with a carriage return character. • A={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, CR} • Q={q 0, q 1, q 2} • q 0: initial state Functional testing 102

FSMs-continued • T: {((q 0, d), q 1), (q 1, CR), q 2)} •

FSMs-continued • T: {((q 0, d), q 1), (q 1, CR), q 2)} • F: {q 2} 4 A state diagram is an easier to understand specification of a state machine. For the above machine, the state diagram appears on the next page. Functional testing 103

State diagram d q 0 d q 1 CR q 2 States indicated by

State diagram d q 0 d q 1 CR q 2 States indicated by circles. State transitions indicated by labeled arrows from one state the another (which could be the same). Each label must be from the alphabet. It is also known as an event. Final state indicated by concentric circles. d: denotes a digit Functional testing 104

State diagram-actions x/y: x is an element of the alphabet and y is an

State diagram-actions x/y: x is an element of the alphabet and y is an action. d/add 10*d to i d/set i to d q 0 q 2 q 1 CR/output i i is initialized to d when the machine moves from state q 0 to q 1. i is incremented by 10*d when the machine moves from q 1 to q 1. The current value of i is output when a CR is encountered. Can you describe what this machine computes? Can you construct a regular expression that describes all strings recognized by this state machine? Functional testing 105

State machine: languages 4 Each state machine recognizes a language. 4 The language recognized

State machine: languages 4 Each state machine recognizes a language. 4 The language recognized by a state machine is the set S of all strings such that: – when any string s in S is input to the state machine the machine goes through a sequence of transitions and ends up in the final state after having scanned all elements of s. Functional testing 106

State diagram-errors d/add 10*d to I d/set I to d q 0 CR/output I

State diagram-errors d/add 10*d to I d/set I to d q 0 CR/output I CR reset q 2 q 1 /ou tpu t er ror q 4 has been added to the set of states. It represents an error state. Notice that reset is a new member added to the alphabet. Functional testing 107

State diagram-program 4 A state diagram can be transformed into a program using case

State diagram-program 4 A state diagram can be transformed into a program using case analysis. Here is a C program fragment that embodies logic represented by the previous state diagram. 4 There is one function for each action. 4 digit is assumed to be provided by the lexical analyzer. Functional testing 108

Program for “integer” state machine /* state is global, with values q 0, q

Program for “integer” state machine /* state is global, with values q 0, q 1, q 2. i is also global. */ void event_digit() { switch (state) case q 0: i=digit; state=q 1; break; case q 1: i=i+10*digit; state=q 1; break; /* perform action. */ /* set next state. */ /* event digit is done. */ /* Add the next digit. */ /*…complete the program. */ Functional testing 109

More examples 4 Let us go over figures 19. 4 and 19. 5 on

More examples 4 Let us go over figures 19. 4 and 19. 5 on pages 308 -309 of the text. Functional testing 110

Checking state diagrams 4 Unreachable state: One that cannot be reached from q 0

Checking state diagrams 4 Unreachable state: One that cannot be reached from q 0 using any sequence of transitions. 4 Dead state: One that cannot be left once it is reached. Functional testing 111

Test requirements 4 Every state must be reached at least once, Obtain 100% state

Test requirements 4 Every state must be reached at least once, Obtain 100% state coverage. 4 Every transition must be exercised at least once. Obtain 100% transition coverage. 4 The textbook talks about duplicate transitions. No transitions are duplicate if the state machine definition we have given is used. Functional testing 112

Example test requirements 4 For the “integer” state machine: – state machine transitions: •

Example test requirements 4 For the “integer” state machine: – state machine transitions: • • • event digit in state q 0 event CR in state q 0 event digit in state q 1 event CR in state q 1 event reset in state q 4 Functional testing 113

More testing of state machines? 4 Yes, it is possible! 4 When we learn

More testing of state machines? 4 Yes, it is possible! 4 When we learn about path coverage we will discuss how more test requirements can be derived from a state diagram. Functional testing 114

Test specifications 4 As before, test specifications are derived from test requirements. 4 In

Test specifications 4 As before, test specifications are derived from test requirements. 4 In the absence of dead states, all states and transitions can be reached by one test. 4 It is advisable not to test the entire machine with one test case. 4 Develop test specifications for our “integer” state machine. Functional testing 115

Decision tables 4 Requirements of certain programs are specified by decision tables. 4 Such

Decision tables 4 Requirements of certain programs are specified by decision tables. 4 Such tables can be used for deriving test requirements and specifications. 4 A decision table is useful when specifying complex decision logic Functional testing 116

Decision tables 4 A decision table has two parts: – condition part – action

Decision tables 4 A decision table has two parts: – condition part – action part 4 The two together specify under what condition will an action be performed. Functional testing 117

Decision table-nomenclature • • C: denotes a condition A: denotes an action Y: denotes

Decision table-nomenclature • • C: denotes a condition A: denotes an action Y: denotes true N: denotes false X: denotes action to be taken. Blank in condition: denotes “don’t care” Blank in action: denotes “do not take the action” Functional testing 118

Bank example 4 Consider a bank software responsible for debiting from an account. The

Bank example 4 Consider a bank software responsible for debiting from an account. The relevant conditions and actions are: • • • C 1: The account number is correct C 2: The signature matches C 3: There is enough money in the account A 1: Give money A 2: Give statement indicating insufficient funds A 3: Call vigilance to check for fraud! Functional testing 119

Decision tables Functional testing 120

Decision tables Functional testing 120

Example-continued 4 A 1 is to be performed when C 1, C 2, and

Example-continued 4 A 1 is to be performed when C 1, C 2, and C 3 are true. 4 A 2 is to be performed when C 1 is true and C 2 and C 3 are false or when C 1 and C 2 are true and C 3 is false. 4 A 3 is to be performed when C 2 and C 3 are false. Functional testing 121

Default rules 4 Are all possible combinations of conditions covered? 4 No! Which ones

Default rules 4 Are all possible combinations of conditions covered? 4 No! Which ones are not covered? 4 We need a default action for the uncovered combinations. A default action could be an error report or a reset. Functional testing 122

Example-test requirements 4 Each column is a rule and corresponds to at least one

Example-test requirements 4 Each column is a rule and corresponds to at least one test requirement. 4 If there are n columns then there at least n test requirements. 4 What is the maximum number of test requirements? Functional testing 123

Example-test specifications 4 For each test requirement find a set of input values of

Example-test specifications 4 For each test requirement find a set of input values of variables such that the selected rule is satisfied. 4 When this test is input to the program the output must correspond to the action specified in the decision table. 4 Should the testing depend on the order in which the conditions are evaluated? Functional testing 124

Summary 4 Specifications, pre-conditions, and post- conditions. 4 Clues, test requirements, and test specifications.

Summary 4 Specifications, pre-conditions, and post- conditions. 4 Clues, test requirements, and test specifications. 4 Clues from code. 4 Test requirements catalog. 4 Equivalence partitioning and boundary value analysis. Functional testing 125

Summary-continued 4 Finite state machine 4 State diagram 4 Events and actions 4 Unreachable

Summary-continued 4 Finite state machine 4 State diagram 4 Events and actions 4 Unreachable and dead states 4 Test requirements and specifications for state machines 4 Decision tables, rules, actions Functional testing 126