Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing Claus Brabrand [ ] ( “FÅP”: First-year Project Course, ITU,

Slides:



Advertisements
Similar presentations
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
Advertisements

CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Claus Brabrand, ITU, Denmark Feb 26, 2008WHITE-BOX TESTING White-Box Testing Claus Brabrand [ ] ( “FÅP”: First-year Project Course, ITU,
Topic 03 Control Statements Programming II/A CMC2522 / CIM2561 Bavy Li.
Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing Claus Brabrand [ ] ( “FÅP”: First-year Project Course, ITU,
1 Control Structures (and user input). 2 Flow of Control The order statements are executed is called flow of control By default, statements in a method.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Claus Brabrand, ITU, Denmark Mar 23, 2009STATIC ANALYSIS (DATA-FLOW ANALYSIS) Static Analysis: Data-Flow Analysis I Claus Brabrand IT University of Copenhagen.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Aalborg Media Lab 23-Jun-15 Software Design Lecture 6 “Conditionals and Loops”
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Conditionals II Lecture 11, Thu Feb
Claus Brabrand, UFPE, Brazil Aug 04, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and.
CSM-Java Programming-I Spring,2005 Control Flow Lesson - 3.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Control Structures A control structure is simply a pattern for controlling the flow of a program module. The three fundamental control structures of a.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
CONTROLLING PROGRAM FLOW
CS 217 Software Verification and Validation Week 7, Summer 2014 Instructor: Dong Si
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Repetition Statements while and do while loops
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Control statements Mostafa Abdallah
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
Application development with Java Lecture 6 Rina Zviel-Girshin.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 8 Java Fundamentals Control Structures Fri.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Structured Programming Structured Programming is writing a program in terms of only 3 basic control structures: sequence selection repetition We have already.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
Control Structures.
Chapter 6 More Conditionals and Loops
White-Box Testing.
CiS 260: App Dev I Chapter 4: Control Structures II.
Expressions and Control Flow in JavaScript
SELECTION STATEMENTS (1)
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Relational, Logical, and Equality Operators
Whitebox Testing.
Whitebox Testing.
Outline Software Development Activities
Chap 7. Advanced Control Statements in Java
Loops CGS3416 Spring 2019 Lecture 7.
Static Analysis: Data-Flow Analysis I
Presentation transcript:

Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing Claus Brabrand [ ] ( “FÅP”: First-year Project Course, ITU, Denmark )

[ 2 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING   successful test case unsuccessful test case Problematic terminology:   successful test case unsuccessful test case Much better terminology: Psychology of Testing (cont’d) Goal: find as many errors as possible ”Testing is the process of executing a program with the intent of finding errors.” vs [cf. ”The Art of Software Testing” (Chap. 2), Glenford J. Myers, 1979]

[ 3 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Testing vs. Debugging (cont’d) Evaluate test results Fix problem (reprogram) Functionality Testing Quality assurance: Perform (functionality) test Debugging Diagnosis: Determine problem? Program: (greater confidence!)   SYSTEMATIC Document test results (confidence?!?) Re

[ 4 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-box vs. Black-box Test White-box Testing: (aka., ”structural testing”) (aka., ”internal testing”) Test focus: source code Black-box Testing: (aka., ”behavioral testing”) (aka., ”external testing”) (aka., ”input-ouput testing” ) Test focus: specification (or intention) Complementary Approaches!!! n = in(); n = n/2; odd(n) n = 3*n+1; out(n); tt ff ~ ? programspec

[ 5 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Test Coverage? Method coverage: Does every method run (at least once)? Statement coverage: Does every statement run (at least once)? Branch coverage: Does every branch run (at least once)? Path coverage: Does every path run (at least once)?

[ 6 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Statement coverage Statement coverage: Does every statement run (at least once)? -Box ”Statement Coverage Testing” is: Efficient (fast) ! Effective (thorough) ! Good for complicated program logic (esp. ”initialization errors”)

Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control Structures & Control Flow Graphs

[ 8 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control Structures Control Structures: Statements (or Expr’s) that affect ”flow of control”: if-else : if : if ( Exp ) Stm 1 else Stm 2 if ( Exp ) Stm Stm 1 Exp truefalse Stm 2 confluence Stm Exp true false confluence The expression must be of type boolean; if it evaluates to true, the given statement is executed, otherwise not. The expression must be of type boolean; if it evaluates to true, Statement-1 is executed, otherwise Statement-2 is executed. [syntax] [semantics] [syntax] [semantics]

[ 9 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control Structures (cont’d) while : for : while ( Exp ) Stm for (Exp 1 ; Exp 2 ; Exp 3 ) Stm Equivalent to: The expression must be of type boolean; if it evaluates to false, the given statement is skipped, otherwise it is executed and afterwards the expression is evaluated again. If it is still true, the statement is executed again. This is continued until the expression evaluates to false. { Exp1; while ( Exp2 ) { Stm Exp3; } } Stm Exp true false confluence Exp 1 ; Exp 2 true false Stm confluence Exp 3 ; [syntax] [semantics] [syntax] [semantics]

[ 10 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Example (Control-Flow Graph) Example Program: Control-Flow Graph: void m(int account, int rate) { account = account + 10; if (account > 100) rate = rate * 2; else rate = rate / 2; out(“account = ” + account + “ rate = ” + rate); } account = account + 10; rate *= 2; rate /= 2; account > 100 true false out(“account = ” + …); confluence

[ 11 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Larger Example public static void main ( String[] args ) { int mi, ma; if (args.length == 0) System.out.println("No numbers"); else { mi = ma = Integer.parseInt(args[0]); for (int i=1; i < args.length; i++) { int obs = Integer.parseInt(args[i]); if (obs > ma) ma = obs; else if (mi < obs) mi = obs; } System.out.println("min=" + mi + "," + "max=" + ma); }} /* 1 if-else */ /* 2 for */ /* 3 if-else */ /* 4 if */ if else for if else if

[ 12 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control-Flow Graph CFG: int mi, ma; System.out.println ("No numbers"); args.length == 0 mi = ma = Integer.parseInt(args[0]); int i=1; i < args.length i++; System.out.println( " min=" + mi + "," + "max=" + ma); int obs = Integer.parseInt(args[i]); obs > ma ma = obs; mi < obs mi = obs; true false true false true false true false

[ 13 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Exercises Program: Exercise 1: Control-Flow Graph Exercise 2: White-Box Testing int factorial(int n) { // iterative version if (n<0) System.out.println(“*** negative number!”); else { int res = 1; for (int i=1; i<=n; i++) { res = res * i; } return res; }

[ 14 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Afl.Opg.: Control-Flow Graph public List merge(List list1, List list2) { ArrayList min; ArrayList max; if (list1.size() > list2.size()) { max = (ArrayList ) list1; min = (ArrayList ) list2; } else { max = (ArrayList ) list2; min = (ArrayList ) list1; } List list3 = new ArrayList (); for (int i=0; i < max.size(); i++) { for (int j=0; j < min.size(); j++) { if (max.get(i) > min.get(j)) { list3.add(min.get(j)); min.remove(j); } list3.add(max.get(i)); } if (min.size() > 0) { list3.addAll(min); } return list3; }

[ 15 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control Structures (cont’d 2 ) do-while : ” ?: ”; ”conditional expression”: ” && ”; ”lazy conjunction” (aka., ”short-cut  ”): ” || ”; ”lazy disjunction” (aka., ”short-cut  ”): switch : switch ( Exp ) { Swb * } case Exp : Stm * break; do Stm while ( Exp ); default : Stm * break; Swb: Exp 1 ? Exp 2 : Exp 3 Exp 1 && Exp 2 Exp 1 || Exp 2

[ 16 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Control Structures (cont’d 3 ) try-catch-finally (exceptions): return / break / continue : ”method invocation”: e.g.; ”recursive method invocation”: e.g.; ”virtual dispatching”: e.g.; try Stm 1 catch ( Exp ) Stm 2 finally Stm 3 f(x) return ;return Exp ; break ;continue ; f(x)