Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS223: Software Engineering Lecture 26: Software Testing.

Similar presentations


Presentation on theme: "CS223: Software Engineering Lecture 26: Software Testing."— Presentation transcript:

1 CS223: Software Engineering Lecture 26: Software Testing

2 Recap Introduction to testing Fault-failure-defect-error White box-black box testing Test report writing

3 Objective After completing this lecture students will be able to o Perform control flow test of their software

4 Control Flow Testing Program instructions are executed in a sequential manner o In the absence of conditional statements o Unless a function is called The execution of a sequence of instructions from the entry point to the exit point of a program unit is called a program path. Ideally, one must strive to execute fewer paths for better effectiveness.

5 Outline of control flow testing Inputs o The source code of a program unit o A set of path selection criteria Examples of path selection criteria o Select paths such that every statement is executed at least once o Select paths such that every conditional statement evaluates to true and false at least once on different occasions

6 Control flow graph

7 Control Flow Graph (CFG) FILE *fptr1, *fptr2, *fptr3; /* These are global variables.*/ int openfiles(){ /* This function tries to open files "file1", "file2", and "file3" for read access, and returns the number of files successfully opened. The file pointers of the opened files are put in the global variables. */ int i = 0; if( ((( fptr1 = fopen("file1", "r")) != NULL) && (i++) && (0)) || ((( fptr2 = fopen("file2", "r")) != NULL) && (i++) && (0)) || ((( fptr3 = fopen("file3", "r")) != NULL) && (i++)) ); return(i); }

8 CFG

9 What paths do I select for testing? Select all paths. Select paths to achieve complete statement coverage. Select paths to achieve complete branch coverage. Select paths to achieve predicate coverage.

10 What paths do I select for testing? Select all paths. Select paths to achieve complete statement coverage. Select paths to achieve complete branch coverage. Select paths to achieve predicate coverage.

11 Path selection criteria FILE *fptr1, *fptr2, *fptr3; /* These are global variables.*/ int openfiles(){ /* This function tries to open files "file1", "file2", and "file3" for read access, and returns the number of files successfully opened. The file pointers of the opened files are put in the global variables. */ int i = 0; if( ((( fptr1 = fopen("file1", "r")) != NULL) && (i++) && (0)) || ((( fptr2 = fopen("file2", "r")) != NULL) && (i++) && (0)) || ((( fptr3 = fopen("file3", "r")) != NULL) && (i++)) ); return(i); }

12 Input Domain

13 Paths executed by the test inputs 1. 2. 3.

14 What paths do I select for testing? Select all paths. Select paths to achieve complete statement coverage. Select paths to achieve complete branch coverage. Select paths to achieve predicate coverage.

15 Statement Coverage It refers to o Executing individual program statements and o Observing the outcome. 100% statement coverage has been achieved if o All the statements have been executed at least once Covering a statement in a program means o Visiting one or more nodes in a CFG

16 What paths do I select for testing? Select all paths. Select paths to achieve complete statement coverage. Select paths to achieve complete branch coverage. Select paths to achieve predicate coverage.

17 What paths do I select for testing? Select all paths. Select paths to achieve complete statement coverage. Select paths to achieve complete branch coverage. Select paths to achieve predicate coverage.

18 Example: Predicate coverage

19 Generating test input How to select input values, such that o When the program is executed with the selected inputs o The chosen paths get executed 1. Input Vector 2. Predicate 3. Path Predicate 4.Predicate Interpretation 5.Path Predicate Expression 6.Generating Input Data from Path Predicate Expression

20 Input Vector It is a collection of all data entities Members of an input vector of a routine can take different forms o Global variables and constants o Files o Contents of registers

21 Predicate A predicate is a logical function evaluated at a decision point The construct OB is the predicate in decision node 5

22 Path Predicate A path predicate is the set of predicates associated with a path. We must know whether the individual component predicates of a path predicate evaluate to true or false in order to generate path forcing inputs.

23 Predicate Interpretation The local variables are not visible outside a function We can easily substitute all the local variables in a predicate with the elements of the input vector The process of symbolically substituting operations along a path in order to express the predicates solely in terms of the input vector and a constant vector.

24 Path Predicate Expression An interpreted path predicate is called a path predicate expression o It is void of local variables o Path forcing input values can be generated by solving the set of constraints in a path predicate expression. o If the constraints can not be solved: infeasible path

25 Data Flow Testing A memory location corresponding to a program variable is accessed in a desirable way It is desirable to verify the correctness of a data value generated for a variable Programmer can perform a number of tests on data values Two types: Static, and Dynamic

26 Data flow anomaly A deviant or abnormal way of doing something The three abnormal situations Type 1: Defined and Then Defined Again Type 2: Undefined but Referenced Type 3: Defined but Not Referenced

27 State transition diagram of a variable

28 Dynamic data flow testing 1. Draw a data flow graph from a program. 2.Select one or more data flow testing criteria. 3.Identify paths in the data flow graph satisfying the selection criteria. 4.Derive path predicate expressions from the selected paths and solve those expressions to derive test input.

29 Thank you Next Lecture: Software Testing


Download ppt "CS223: Software Engineering Lecture 26: Software Testing."

Similar presentations


Ads by Google