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
What type of data can a variable hold?
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
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,
Claus Brabrand, ITU, Denmark STATIC ANALYSIS (DATA-FLOW ANALYSIS)Apr 09, 2008 Static Analysis: Data-Flow Analysis IV Claus Brabrand ITU - IT University.
 Demonstrate use of a “for loop” in the design and development of a Java program to calculate the total of a one-dimensional array of 6 integers.  Design.
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.
Claus Brabrand, ITU, Denmark Mar 23, 2009STATIC ANALYSIS (DATA-FLOW ANALYSIS) Static Analysis: Data-Flow Analysis I Claus Brabrand IT University of Copenhagen.
Java Programming (Chapter 1). Java Programming Classes, Types, and Objects.
1 Repetition structures Overview while statement for statement do while statement.
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops III Lecture 20, Fri Mar
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing Claus Brabrand [ ] ( “FÅP”: First-year Project Course, ITU,
Jan Art of Programming Yangjun Chen Dept. Business Computing University of Winnipeg.
Conditionals, Loops, and Other Statements CS-2301 D-term Conditionals, Loops, and Other Kinds of Statements CS-2301 System Programming C-term 2009.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
Claus Brabrand, UFPE, Brazil Aug 04, 2010DATA-FLOW ANALYSIS Claus Brabrand ((( ))) Associate Professor, Ph.D. ((( Programming, Logic, and.
UNIT II Decision Making And Branching Decision Making And Looping
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
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.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Chapter 5 – Part 3 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved5-2 Outline The if Statement and Conditions Other Conditional.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Methods. Methods also known as functions or procedures. Methods are a way of capturing a sequence of computational steps into a reusable unit. Methods.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
CSE 110 Review Session Hans Hovanitz, Kate Kincade, and Ian Nall.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
CONTROL STRUCTURE Chapter 3. CONTROL STRUCTURES ONE-WAY SELECTION Syntax: if (expression) statement Expression referred to as decision maker. Statement.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
Discrete Maths: Invariant/2 1 Discrete Maths Objectives – –to show the use of induction for proving properties of code involving loops use induction.
Comp1004: Programming in Java I Variables - Primitives, Objects and Scope.
Lecture 6: Methods MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture, you will learn… What a method is Why we use.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
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.
White-Box Testing Statement coverage Branch coverage Path coverage
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Comp1004: Introduction III Java. Content How Java Works: The JVM Writing a Class in Java – Class – Member Variables – Method – Statement Magic incantations.
CSC111 Quick Revision.
Control Structures.
Faults, Errors, Failures CS 4501 / 6501 Software Testing
TK1114 Computer Programming
SELECTION STATEMENTS (1)
Unit 3 - The while Loop - Extending the Vic class - Examples
Whitebox Testing.
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
Week 7 CS 302 Jim Williams.
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 )

Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing Method

[ 3 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Statement Coverage Testing if : TEST condition true and false if-else : TEST condition true and false while : TEST zero, one, more-than-one iterations in loop for : TEST zero, one, more-than-one iterations in loop

[ 4 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING White-Box Testing ”Coverage Table”: ”Expectancy Table”: Input property account > 90 account <= 90 Data set A B Choice 1 ife true false Data set A B   Input (98,3) (76,4) Expected output ”a=108, r=6” ”a= 86, r=2” Actual output ”a=108, r=6” ”a= 86, r=2” = void m(int account, int rate) { account = account + 10; if (account > 100) // 1 ife rate = rate * 2; else rate = rate / 2; out(“account = ” + account + “ rate = ” + rate); } Testing the world famous method: ”insert-$10-then-double-rate-if-account- exceeds-$100-otherwise-halve-rate”

[ 5 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING ”Coverage Table”: Coverage Table Input property No numbers At least one number Exactly one number Exactly two numbers At least three numbers N > current max N  current max N  cur max & N > cur min N  cur max & N  cur min Data set A B B C E C D E (3 rd num) E (2 nd num) Choice 1 ife true false 2 for zero-times once more-than-once 3 ife true false 4 if true false

[ 6 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING ”Expectancy Table”: Expectancy Table Data set A B C D E      Advice: Avoid expected 0’s (i.e., zeroes) (Default value in many languages.) Advice: Avoid reusing same numbers in tests (Data layout sometimes reuse old memory.) Input  [17] [27,29] [39,37] [49,47,48] Expected output ”no numbers” ”min=17,max=17” ”min=27,max=29” ”min=37,max=39” ”min=47,max=49” Actual output ”no numbers” ”min=17,max=17” ”min=27,max=29” ”min=39,max=39” ”min=49,max=49” =

[ 7 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING 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); }} Debugging ’ D ’ then reveals… /* 1 if-else */ /* 2 for */ /* 3 if-else */ /* 4 if */ if else for if else if Should have been: (obs < mi)

[ 8 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Re-Test ! …as debugging often introduces new errors ! Fixed Program: Coverage Table: Expectancy Table:  Recall: no guarantee!

[ 9 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Another Example public static void main ( String[] args ) { int mi1 = 0, mi2 = 0; if (args.length == 0) /* 1 if-else */ System.out.println("No numbers"); else { mi1 = Integer.parseInt(args[0]); if (args.length == 1) /* 2 if-else */ System.out.println("Smallest = " + mi1); else { int obs = Integer.parseInt(args[1]); if (obs < mi1) /* 3 if */ { mi2 = mi1; mi1 = obs; } for (int i = 2; i < args.length; i++) { /* 4 for */ obs = Integer.parseInt(args[i]); if (obs < mi1) /* 5 if-else */ { mi2 = mi1; mi1 = obs; } else if (obs < mi2) /* 6 if */ mi2 = obs; } System.out.println("The two smallest are: " + mi1 + " and " + mi2); } } }

[ 10 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Coverage Table Choice Input property Data set 1 ife true No numbers 1 ife false At least one number 2 ife true Exactly one number 2 ife false At least two numbers 3 if true 2 nd number ≥ 1 st number 3 if false 2 nd number < 1 st number 4 for zero-times Exactly two numbers 4 for once Exactly three numbers 4 for more-than-once At least four numbers 5 ife true 3 rd number < current min 5 ife false 3 rd number ≥ current min 6 if true 3 rd ≥ cur min & 3 rd < 2 nd least 6 if false 3 rd ≥ cur min & 3 rd ≥ 2 nd least ABBCCDDEHEFFGABBCCDDEHEFFG

[ 11 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Expectancy Table Data set Input Expected output = Actual output A  ”no numbers” ”no numbers” B [17] ”17” ”17” C [27,29] ”27 and 29” ”27 and 0” D [39,37] ”37 and 39” ”37 and 39” E [49,48,47] ”47 and 48” ”47 and 48” F [59,57,58] ”57 and 58” ”57 and 58” G [67,68,69] ”67 and 68” ”67 and 0” H [77,78,79,76] ”76 and 77” ”76 and 77”         Debugging reveals that variable ” mi2 ” erroneously retains initialization (0).

[ 12 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Debugging public static void main ( String[] args ) { int mi1 = 0, mi2 = 0; if (args.length == 0) /* 1 if-else */ System.out.println("No numbers"); else { mi1 = Integer.parseInt(args[0]); if (args.length == 1) /* 2 if-else */ System.out.println("Smallest = " + mi1); else { int obs = Integer.parseInt(args[1]); if (obs < mi1) /* 3 if */ { mi2 = mi1; mi1 = obs; } for (int i = 2; i < args.length; i++) { /* 4 for */ obs = Integer.parseInt(args[i]); if (obs < mi1) /* 5 if-else */ { mi2 = mi1; mi1 = obs; } else if (obs < mi2) /* 6 if */ mi2 = obs; } System.out.println("The two smallest are: " + mi1 + " and " + mi2); } } } mi2 = obs; Re-Test: 

[ 13 ] Claus Brabrand, ITU, Denmark Feb 17, 2009WHITE-BOX TESTING Exercises Program (Factorial, iterative version): Exercise 1: Control-Flow Graph Exercise 2: White-Box Testing int factorial(int n) throws BadUserException { if (n<0) throw BadUserException; 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 Afleveringsopgave (i grupper) public List merge(List list1, List list2) { // invariant: we ASSUME list1 and list2 are sorted! 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; } Note: Do not forget to always re-test after debugging!