Вы находитесь на странице: 1из 14

Loop Testing

Loop Testing?
Loop testing is a white box testing technique that focuses exclusively on the validity of loop constructs.

Goal of loop testing


The goal of loop testing is to test while-do, repeat-until, or do-while! and any other loops in a progra" thoroughly - by trying to ensure that each is executed at #ini"al n!, typical, and if this is defined! "axi"al values "! - and to try to $$brea%&& the progra", by trying to have a loop executed with a ' fewer than "ini"u", n-(! ' as well as a larger than "axi"al, ")(! ' nu"ber of iterations. "-n!

Types of Loops
(.*i"ple loops-Simple Loops are loops whose loop bodies contain no other loops +. ,ested loops-Nested Loops are co"binations of loops such that each is contained inside the loop body of the next. -. .oncatenated loops /. 0nstructured loops

Guidelines for Loop Testing


The $$guidelines&& for loop testing consist of lists of test cases that should be included for each type of loop.

Guidelines for Simple Loops


Try to design a test in which the loop body isn&t executed at all. Try to design a test in which the loop body is executed exactly once. Try to design a test in which the loop body is executed exactly twice. 1esign a test in which a loop body is executed so"e $$typical&& nu"ber of ti"es. 2f there is an upper bound, n, on the nu"ber of ti"es the loop body can be executed, then the following cases should also be applied. 1esign a test in which the loop body is executed exactly n-( ti"es. 1esign a test in which the loop body is executed exactly n ti"es. Try to design a test causing the loop body to be executed exactly n)( ti"es.

3xa"ple
44range 5 to (5 int n6(5 for int i657 i86n7i))! 9 print :welco"e;!7 <

Test case for si"ple loop testing


Test case ID 1 # % Value of I range(n-) (0-10) n-1=-1 0 1 Expected outcome loop body sn!t executed at all" Executed once $elcome Executed t& ce $elcome &elcome Executed ( t mes Executed 10 t mes Executed 11 t mes loop body sn!t executed at all" Actual results

' ( + ,

' )-1 t mes * ) t mes 10 )-1 t mes 11

Guidelines for Nested Loops


start at the inner "ost loop. *et all other loops to "ini"al non =ero values. .onduct si"ple loop test for inner "ost loop while holding outer loops at their "ini"u" iteration para"eter values. >or% outward, conducting tests for the next loop, but %eep all other outer loops to "ini"al values and nested loops to typical values. .ontinue this until all loops have been tested.

3xa"ple
44range 5 to (5 int n6(5 for int i657 i86n7i))! 9 for int ?6(7 i86@7?))! 9 print :welco"e;!7 < <

Test case for ,ested loop testing


Test case ID 1 # % ' ( + , Value of I range(n-) (0-10) Expected outcome Actual results

Guidelines for Concatenated Loops


2f the loops are $$independent,&& so that the nu"ber of iterations used for one loop doesn&t depend on the nu"ber of iterations used for any other s!, then it is sufficient to apply the guidelines for si"ple loops to each of the loops in the sequence. An the other hand, if the nu"ber of iterations used for one loop does depend on the nu"ber of iterations used for another, then the following guidelines should be used instead. .onduct $$si"ple loop tests&& for the bottom or $$last&&! loop in the sequence, holding the nu"ber of iterations of the higher or $$previous&&! loops at "ini"al values. >or% up toward the top loop, considering each loop in turn, and applying $$si"ple loop tests&& for each loop in turn, %eeping the nu"ber of iterations of upper loops at "ini"al values and %eeping the nu"ber of iterations of lower loops at typical values.

Test case for concatenated loop testing


Test case ID 1 # % ' ( + , Value of I range(n-) (0-10) Expected outcome Actual results

0nstructured loops
This class of loops should be redesigned to reflect the use of structured progra""ing constructs.