1.26k likes | 1.52k Views
Graduate Assistants :. Baskar Sridharan Ramkumar Natarajan. Software Testing Day 2: Functional Testing. Aditya P. Mathur Purdue University August 12-16 @ Guidant Corporation Minneapolis/St Paul, MN. Last update: July 23, 2002. Course Organization. Part I: Monday Preliminaries
E N D
Graduate Assistants: Baskar Sridharan Ramkumar Natarajan Software TestingDay 2: Functional Testing Aditya P. Mathur Purdue University August 12-16 @ Guidant Corporation Minneapolis/St Paul, MN Last update: July 23, 2002
Course Organization Part I: Monday Preliminaries Part II: Tuesday Functional Testing Part III:Wednesday Test Assessment and improvement Part IV: Thursday Robustness, performance, and GUI testing Part V: Friday Reliability and testprocess Functional testing
Part II: Functional testing • 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
What is functional testing? • When test inputs are generated using program specifications, we say that we are doing functional testing. • Functional testing tests how well a program meets the functionality requirements. Functional testing
The methodology • The derivation of test inputs is based on program specifications. • Clues are obtained from the specifications. • Clues lead to test requirements. • Test requirements lead to test specifications. • Test specifications are then used to actually execute the program under test. Functional testing
Test methodology Specifications Clues Expected behavior Program output is correct Test requirements Oracle or Test specifications Program has failed; make a note and proceed with testing or get into the debug mode. Test driver Until specs. Exhausted. Actual behavior Program Functional testing
Specifications • Inputs and tasks: • Given inputs • Perform tasks Functional testing
Specifications-continued • Input properties • Input • must satisfy • Function f is a pre-condition on input Functional testing
Specifications-continued • 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
Specification: example • 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
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
Preconditions for sort • Validated: • N>0 • On failure return -1; sorting considered unsuccessful. • Assumed: • The input sequence contains N integers. • The output area has space for at least N integers. Functional testing
Deriving pre-conditions • Pre-conditions result from properties of inputs. • Example: • alpha_sequence(name) alpha_sequence is the string obtained from name by removing all characters other then A-Z, and a-z. Thus, if name is “A12C” then alpha_name is “AC”. Functional testing
Deriving pre-conditions-continued • This leads to the following pre-condition: • Validated: the string alpha_sequence(name) is shorter than name. • On failure: print “invalid name”. • This property could also lead to the pre-condition: • Assumed: the string alpha_ sequence(name) is shorter than name. Functional testing
Post-conditions • A post-condition specifies a property of the output of a program. • The general format of a post-condition is: • if condition then effect-1 {else effect-2} • Example: • For the sort program a post-condition is: • ifN>0 then {the output sequence has the same elements as in the input sequence and in ascending order.} Functional testing
Post-condition-continued • This could be stated more formally as: • ifN>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
Post-condition-continued • Another example: • if (A=B) and (B=C) then return “equilateral”; • Can you complete the above post-condition for a program that is required to classify a triangle given the length of three sides? • Convention: We will not nest if-then-else statements while specifying a post-condition. Functional testing
Incompleteness of specifications • Specifications may be incomplete or ambiguous. • 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
Ambiguous specifications • 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
Clues: summary • 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
Clues-continued • Ideally variables, operations and definitions should be a part of at least one pre- or post-condition. • However, this may not be the case as specifications are not always written formally. • Hence look out for variables, operations, and definitions within a specification! Functional testing
Test requirements • A test requirement is a description of how to test the program that is under test. • 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
Test requirements-derivation • Test requirements are derived from clues. • For example, consider the following pre-conditions (clues): • Assumed: A, B, and C are lengths • Validated: A>0, B>0, C>0 • These pre-conditions on A, B, and C lead to the test requirement given above. Functional testing
Test requirements-derivation • Note that we have clumped pre-condition for each input variable into one condition. This is being done only for inconvenience. • It is recommended that pre-conditions be separated for each variable. Functional testing
Test requirements-derivation • 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. • 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
Test requirements-derivation • Post-conditions also lead to test requirements. • 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
Compound validated pre-conditions • Compound pre-conditions are ones that use the and or or connectors. • Examples: validated compound pre-conditions: • Pre-condition: A and B • Pre-condition: user places the mouse over the name field and clicks it. Functional testing
Compound validated pre-conditions • The first of the above pre-conditions leads to four requirements: • A true, B true (This is the validated part) • A false, B true (This and the rest are failures) • A true, B false • A false, B false • You may work out the requirements for compound pre-condition with the or connector. Functional testing
Compound validated pre-conditions • Compound validated pre-conditions could become quite complex. • Example: (A and (B or C)) • Brute force method will lead to 8 test requirements. Functional testing
Compound validated pre-conditions • In general this will lead to too many test requirements. • We can prune them by leaving out those requirements that are unlikely to reveal a program error. • For example, consider the validated pre-condition: A or B. Functional testing
Pruning test requirements • There are four possible test requirements: • A true, B true • A false, B true • A true, B false • A false, B false • 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
Possible errors • 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
Possible errors-continued • Or use a wrong logical operator as in: if (!(A && B)) exit_with_error(“Error: A is %d, B is %d”, A, B); • Let us analyze how the four different tests will perform in each of the four implementations: one correct, and three incorrect ones. Functional testing
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 F T T F F F T T T T T T F F F F Notice this one: will it help find any of the three possible errors? Functional testing
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
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
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 the then branch of the if condition. Functional testing
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. • Thus, all four test inputs are likely to be useful. Functional testing
Truth table analysis-continued • However, if we were to check for the correct implementation of the condition A or B, then only the first two inputs are necessary. • 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
Assumed pre-conditions • Each assumed pre-condition is likely to result in a test requirement. • 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
Assumed pre-conditions • These can be simplified to: • MODE is “on ground” • MODE is “flying” Functional testing
Clues from code? • Yes, clues can also be derived by scanning the code. • However, such clues might be redundant and incomplete if coverage measurement and use is planned. • In the absence of coverage measurement, it is a good idea to scan the code and find clues. Functional testing
Clues from code-continued • Examine internal variables. These may lead to new test requirements. • 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
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. • Another example: Consider the sort program for which we have seen the specifications. Functional testing
Clues from code-continued • The specifications do not indicate what algorithm is to be used for sorting the input array. • 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
Clues from code-continued • 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 • Later we will see how this clue and requirements might be derived, with certainty, using branch coverage. Functional testing
Test requirements checklist • Obtaining clues and deriving test requirements can become a tedious task. • To keep it from overwhelming us it is a good idea to make a checklist of clues. • This checklist is then transformed into a checklist of test requirements by going through each clue and deriving test requirements from it. Functional testing
Test specifications • A test requirements indicates “how” to test a program. But it does not provide exact values of inputs. • A test requirement is used to derive test specification, which is the exact specification of values of input and environment variables. Functional testing
Test specifications-continued • There may not be a one-to-one correspondence between test requirements and test specifications. • A test requirement checklist might contain 50 entries. These might result in only 22 test specifications. • The fewer the tests the better but only if these tests are of good quality! Functional testing
Test specifications-continued • We will discuss test quality when discussing test assessment. • 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