DAIMI(c) Henrik Bærbak Christensen1 White-box Testing Let us open the box...

Slides:



Advertisements
Similar presentations
Lecture 2: testing Book: Chapter 9 What is testing? Testing is not showing that there are no errors in the program. Testing cannot show that the program.
Advertisements

White Box and Black Box Testing Tor Stålhane. What is White Box testing White box testing is testing where we use the info available from the code of.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Lecture 11 Instructor Paulo Alencar.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
White Box Testing Techniques Dynamic Testing. White box testing(1) Source code is known and used for test design While executing the test cases, the internal.
DAIMI(c) Henrik Bærbak Christensen1 BlackBox Testing based on Specification.
Ch6: Software Verification. 1 Statement coverage criterion  Informally:  Formally:  Difficult to minimize the number of test cases and still ensure.
Chapter 8: Path Testing Csci 565.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
Software Testing and Quality Assurance
Software Testing and Quality Assurance White Box Testing.
Testing an individual module
SOFTWARE TESTING WHITE BOX TESTING 1. GLASS BOX/WHITE BOX TESTING 2.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
White Box Testing.  Path yang berbeda dalam modul software akan dibentuk oleh pilihan kondisional statement seperti IF-THEN-ELSE atau DO WHILE atau DO.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Software Systems Verification and Validation Laboratory Assignment 3
System/Software Testing
CMSC 345 Fall 2000 Unit Testing. The testing process.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
Coverage – “Systematic” Testing Chapter 20. Dividing the input space for failure search Testing requires selecting inputs to try on the program, but how.
1 Software testing. 2 Testing Objectives Testing is a process of executing a program with the intent of finding an error. A good test case is in that.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
CS /51 Illinois Institute of Technology CS487 Software Engineering Software Testing Techniques Mr. David A. Lash.
Agenda Introduction Overview of White-box testing Basis path testing
1 Software Testing. 2 Path Testing 3 Structural Testing Also known as glass box, structural, clear box and white box testing. A software testing technique.
Black Box Testing Techniques Chapter 7. Black Box Testing Techniques Prepared by: Kris C. Calpotura, CoE, MSME, MIT  Introduction Introduction  Equivalence.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
WHITE BOX TESTING IS4500 Copyright © 2012 by The Cathris Group and Martin J. Schedlbauer. All Rights Reserved. Do Not Duplicate or Distribute Without Written.
Software Construction Lecture 19 Software Testing-2.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Chapter 9: Path Testing Csci 565 Spring Objectives  Decision-to-decision path (DD-Paths)  Test Coverage Metrics  Basis Path Testing  Observation.
Structural Coverage. Measurement of structural coverage of code is a means of assessing the thoroughness of testing. Such metrics do not constitute testing.
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
White-Box Testing Statement coverage Branch coverage Path coverage
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
CS223: Software Engineering Lecture 26: Software Testing.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
White Box Testing. Agenda White-box vs Black-box Program Flow Controls White-box Test Methods Exercises Complexity Q&A.
Testing Integral part of the software development process.
Software TestIng White box testing.
Software Testing.
Software Testing.
Control Flow Testing Handouts
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Outline of the Chapter Basic Idea Outline of Control Flow Testing
CONTROL FLOW TESTING.
Structural testing, Path Testing
White-Box Testing.
CHAPTER 4 Test Design Techniques
UNIT-IV ECS-602 Software engineering PART-I
UNIT-4 BLACKBOX AND WHITEBOX TESTING
“White box” or “glass box” tests
White-Box Testing.
Structural Coverage.
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Control Structure Testing
Structural Coverage.
Whitebox Testing.
Whitebox Testing.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Unit III – Chapter 3 Path Testing.
Presentation transcript:

DAIMI(c) Henrik Bærbak Christensen1 White-box Testing Let us open the box...

DAIMI(c) Henrik Bærbak Christensen2 White-box The idea in white-box/glass-box/structural testing is that you look “inside” – at the structure of the code. If we know the code, chances are that we can develop test cases that “exercise” all aspects of it – that ensures that all structural elements are working. White-box (WB) is also called structural testing.

DAIMI(c) Henrik Bærbak Christensen3 Program structures Basically any program is a combination of only three structures, or basic primes –sequential: a block of code {...} –decision: a switchif, switch,... –iteration: a loopwhile, repeat, do,... WB focus on these basic primes and allow us to –evaluate test sets with respect to their ability to exercise these structures –thus – evaluate quality of test sets –and thus judge of a test set should be improved

DAIMI(c) Henrik Bærbak Christensen4 Adequacy A necessary result of this focus is on adequacy (Da: Tilstrækkelighed(?)) Example: –A test set T ensures that 100% of all statements in the production code P are executed. –T is statement adequate for P. –If less than 100% are executed then T is not statement adequate for P.

DAIMI(c) Henrik Bærbak Christensen5 Criteria There are numerous adequacy criteria. WB focus on program-based criteria but others are useful also in BB and other types of testing. WB criteria –statement coverage –decision coverage –path coverage, and many more Other types of criteria –use case coverage (system level) –interface coverage (integration level)

DAIMI(c) Henrik Bærbak Christensen6 Aspects of WB WB look at code –Corollary: WB does not start until late in the development process BB can be started earlier than WB –Corollary: WB is only feasible for smaller UUTs –because the flow graphs explode in large units BB can be used all the way to system level

DAIMI(c) Henrik Bærbak Christensen7 WB Coverage types Overall there are a number of metrics for coverage: –statement coverage –decision coverage –condition coverage –decision/statement coverage –multiple-condition coverage –path coverage The all relate to the flow graph of code.

DAIMI(c) Henrik Bærbak Christensen8 Flow graph The flow graph is simply the route diagrams that has gone out of fashion. It defines a graph where nodes are basic primes (block, decision, iteration) and edges are control flow between them (the ProgramCounter ).

DAIMI(c) Henrik Bærbak Christensen9 Example code Danish mellemskat Mellemskat is a 6 % tax in 2003 Mellemskatten is calculated based on personal income plus positive net capital income. If a married person has negative net capital income, this amount is deducted in the spouse's positive net capital income before the mellemskat is calculated.

DAIMI(c) Henrik Bærbak Christensen10 Initial design public static int calculateMellemskat(Taxpayer t) Let us define a taxation basis which is the amount that the tax is calulated on. Calculations involve: t.netCapitalIncome()nci t.getSpouse()s t.getSpouse().netCapitalIncome()s.nci posNetCapitalIncomepos

DAIMI(c) Henrik Bærbak Christensen11 Mr. BrightGuy’s first shot public static int calculateMellemskat(Taxpayer t) { int posNetCapitalIncome = 0; if ( t.netCapitalIncome() > 0 ) { posNetCapitalIncome = t.netCapitalIncome(); } if ( t.getSpouse() != null || t.getSpouse().netCapitalIncome() < 0 ) { posNetCapitalIncome = t.netCapitalIncome() + t.getSpouse().netCapitalIncome(); } int taxationbasis = t.personalIncome() + posNetCapitalIncome;

DAIMI(c) Henrik Bærbak Christensen12 Flow Graph

DAIMI(c) Henrik Bærbak Christensen13 Statement coverage Statement coverage: Require every statement in the program to be executed at least once Exercise: –which path satisfy SC criterion?

DAIMI(c) Henrik Bærbak Christensen14 Statement coverage SC criterion is pretty weak. Path ace is enough. TC: nci = +1000; s.nci = –expected tb: 0 –tb = i.e. defect detected –however, not all defects uncovered ! s = null will result in error, as second condition in second decision will throw an exception.

DAIMI(c) Henrik Bærbak Christensen15 Decision coverage Decision coverage (branch coverage): Require each decision has a true and false outcome at least once Decision 1: –nci > 0 Decision 2 –s!=null OR s.nci < 0 Exercise: –which paths satisfy DC criterion?

DAIMI(c) Henrik Bærbak Christensen16 Decision coverage DC criterion is better TC1: D1 true D2 true TC2: D1 false D2 false Which relates to the paths –ace abd TC1: –nci = +1000; s.nci = TC2: –nci = -2000; s == null –expected tb = 0 break down, ie. defect discovered –however, a defect still uncovered: nci < 0 and s.nci < 0; expect tb = 0 is not tested.

DAIMI(c) Henrik Bærbak Christensen17 Decision coverage Usually decision coverage satisfy statement coverage. However, beware of –exception handling code because the switch is not apparent in the code! –thus exception handling statements are not covered... –and some exotic cases from forgotten languages assembler multi entry procedures !

DAIMI(c) Henrik Bærbak Christensen18 Condition coverage Condition coverage: Require each condition in a decision takes all possible outcomes at least once C1: nci > 0 C2: s != null C3: s.nci < 0 Exercise: –which paths satisfy CC criterion?

DAIMI(c) Henrik Bærbak Christensen19 Condition coverage Condition table –nci > 0;nci <= 0 –s != null;s == null –s.nci = 0 Paths: –ace: C1, C2, C3 –abd: !C1, !C2, !C3 Test Cases that satisfy CC –nci=-1000; s=null; ”s.nci = +2000” –nci =+1000; s!=null; s.nci =-2000 –expected tb for both: tb = 0 –still nci<0 and s.nci<0 defect not tried.

DAIMI(c) Henrik Bærbak Christensen20 Condition coverage The example case here is actually not very good at showing CC as the two conditions in the decision is coupled. CC is more relevant when they are independent. Artificial example: –if ( s != null || nci > ) Then DC is satisfied with (both decision outcomes tried) –s != null; nci <= –s != null; nci > while CC require for instance (both condition outcomes tried) –s = null; nci <= –s != null; nci > 10000

DAIMI(c) Henrik Bærbak Christensen21 Condition Coverage Perhaps somewhat surprising... Condition coverage does generally not satisfy Decision Coverage. Consider a branch if ( C1 && C2 ) { B } Then test cases –TC1: !C1, C2TC2: C1, !C2 will satisfy CC –(both outcomes for both conditions) but not DC nor SC! –decision is always false; B is never executed...

DAIMI(c) Henrik Bærbak Christensen22 Decision/Condition Coverage Combine the two to get a stronger coverage: Decision/Condition coverage. However, often conditions mask each other –A && B && Cif A==false then B and C not evaluated –A || B || Cif A==true then B and C not evaluated in all languages with short-curcuit boolean evaluation like C, Java We have this already in the defective OR if ( t.getSpouse() != null || t.getSpouse().netCapitalIncome() < 0 ) which means the last condition never has any effect: if t has a spouse, then path e is taken no matter what spouse’s net capital income is…

DAIMI(c) Henrik Bærbak Christensen23 DCC Coverage In our case DCC is already achieved Paths: –ace: C1, C2, C3 –abd: !C1, !C2, !C3 CC –all Cx in both Cx and !Cx DC –both if’s in both True and False Still: miss the ‘abe’ path 

DAIMI(c) Henrik Bærbak Christensen24 Multiple-condition coverage Multiple-condition coverage: Require all possible combinations of condition outcomes in each decision are invoked at least once. C1, C2, C3 !C1, C2, C3 C1, !C2, C3 !C1, !C2, C3 C1, C2, !C3 !C1, C2, !C3 etc. All in all 2^3 = 8 outcomes

DAIMI(c) Henrik Bærbak Christensen25 Multiple-condition coverage The !C1, C2, C3 is –nci<0, s!= null, s.nci < 0 that would thus generate the test case we have missed for path ’abe’.

DAIMI(c) Henrik Bærbak Christensen26 Multiple-condition coverage Multiple-condition coverage satisfy DCC.

DAIMI(c) Henrik Bærbak Christensen27 Path Testing Path testing (Da: sti test) deals with paths in the UUT. –Full path coverage: All possible paths are tested infeasible: for(int i; i < n; n++) {} has 2^32 possible paths! –Independent graph (iteration count as branch) start with the simplest path add paths that include a new edge, until no new edges

DAIMI(c) Henrik Bærbak Christensen28 –Example: abd = simplest acd = c edge added ace = e edge added; no more unused edges Define test cases for each path –“reasonable sure” of DC and SC

DAIMI(c) Henrik Bærbak Christensen29 Discussion White box testing does not address defects by missing paths and data issues –input: nci = -1000; s.nci = –expected tb = 0; but output tb = White-box techniques view each decision as isolated problems; while many defects comes from their interaction. Black-box techniques are more focused on interactions; and I find that WB techniques should be used to augment a base of BB test cases…