White-Box Testing Techniques

Similar documents
MTAT : Software Testing

Test design techniques

Software Testing TEST CASE SELECTION AND ADEQUECY TEST EXECUTION

MSc Software Testing MSc Prófun hugbúnaðar

(See related materials in textbook.) CSE 435: Software Engineering (slides adapted from Ghezzi et al & Stirewalt

MTAT : Software Testing

MTAT : Software Testing

MTAT : Software Testing

MSc Software Testing and Maintenance MSc Prófun og viðhald hugbúnaðar

STRUCTURAL TESTING. AKA White Box Testing. Thanks go to Andreas Zeller for allowing incorporation of his materials. F. Tip and M.

Using the code to measure test adequacy (and derive test cases) Structural Testing

LECTURE 11 TEST DESIGN TECHNIQUES IV

Software Testing Fundamentals. Software Testing Techniques. Information Flow in Testing. Testing Objectives

Introduction to Dynamic Analysis

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

Testing Methods: White Box Testing II

Aerospace Software Engineering

STRUCTURAL TESTING. AKA White Box Testing. Thanks go to Andreas Zeller for allowing incorporation of his materials. F. Tip and M.

CS 520 Theory and Practice of Software Engineering Fall 2018

1 Black Box Test Data Generation Techniques

Structural Testing. (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 1

Second assignment came out Monday evening. Find defects in Hnefetafl rules written by your classmates. Topic: Code Inspection and Testing

What is Structural Testing?

Feasibility of Testing to Code. Feasibility of Testing to Code. Feasibility of Testing to Code. Feasibility of Testing to Code (contd)

Program Analysis. Program Analysis

Subject Software Testing Structural Testing

Structural Testing. Testing Tactics. Why Structural? Structural white box. Functional black box. Structural white box. Functional black box

Software Testing. Lecturer: Sebastian Coope Ashton Building, Room G.18

Lecture 18: Structure-based Testing

What is software testing? Software testing is designing, executing and evaluating test cases in order to detect faults.

Software Testing part II (white box) Lecturer: Giuseppe Santucci

Why testing and analysis. Software Testing. A framework for software testing. Outline. Software Qualities. Dependability Properties

MTAT : Software Testing

Software Testing. Software Testing

Getting those Bugs Out --Software Testing

Testing Theory. Agenda - What will you learn today? A Software Life-cycle Model Which part will we talk about today? Theory Lecture Plan

Advanced Software Testing Understanding Code Coverage

MTAT : Software Testing

Principles of Software Construction: Objects, Design, and Concurrency (Part 2: Designing (Sub )Systems)

Structural Testing. Testing Tactics. Why Structural? Structural white box. Functional black box. Structural white box. Functional black box

Lecture 10: Introduction to Correctness

Testing Tactics. Structural Testing. Why Structural? Why Structural? Functional black box. Structural white box. Functional black box

7. Testing and Debugging Concurrent Programs

10. Software Testing Fundamental Concepts

UNIT-4 Black Box & White Box Testing

Information Systems. Software Engineering. MCQ - Part 2

Program Correctness and Efficiency. Chapter 2

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

1 Visible deviation from the specification or expected behavior for end-user is called: a) an error b) a fault c) a failure d) a defect e) a mistake

CMPSCI 521/621 Homework 2 Solutions

UNIT-4 Black Box & White Box Testing

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013!

Programming Logic and Design Sixth Edition

Darshan Institute of Engineering & Technology for Diploma Studies

Software Engineering and Scientific Computing

SE 3S03. Zahra Ali. Week of Feb 22, 2016

Test Case Specifications and Test adequacy. Research Methods - Barbara Russo SwSE - Software and Systems Engineering

Introduction To Software Testing. Brian Nielsen. Center of Embedded Software Systems Aalborg University, Denmark CSS

Introduction to Software Testing Chapter 5.1 Syntax-based Testing

From MC/DC to RC/DC: Formalization and Analysis of Control-Flow Testing Criteria

Checking Multiple Conditions

SE 3S03 - Tutorial 10. Helen Brown. Week of Mar 23, 2015

Page 1. Reading assignment: Reviews and Inspections. Foundations for SE Analysis. Ideally want general models. Formal models

Verification and Validation

Verification and Validation

In this Lecture you will Learn: Testing in Software Development Process. What is Software Testing. Static Testing vs.

An Introduction to Systematic Software Testing. Robert France CSU

Testing. Unit, integration, regression, validation, system. OO Testing techniques Application of traditional techniques to OO software

Black-box Testing Techniques

Testing & Continuous Integration. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 20 03/19/2010

Written exam TDDD04 Software Testing

Lecture 2. White- box Tes2ng and Structural Coverage (see Amman and Offut, Chapter 2)

Software Verification and Validation. Prof. Lionel Briand Ph.D., IEEE Fellow

Part 5. Verification and Validation

Software Testing. Massimo Felici IF

Software Testing for Developer Development Testing. Duvan Luong, Ph.D. Operational Excellence Networks

Topics in Software Testing

White-Box Testing Techniques II

Darshan Institute of Engineering & Technology Unit : 9

SOFTWARE TESTING-UNIT 2

Software processes, quality, and standards White-box testing

People tell me that testing is

Lecture 2. White- box Tes2ng and Structural Coverage (see Amman and Offut, Chapter 2)

Chapter 11, Testing. Using UML, Patterns, and Java. Object-Oriented Software Engineering

Testing & Debugging TB-1

Module 2: Choice and Iteration

White Box Testing with Object Oriented programming

COMPILER DESIGN - CODE OPTIMIZATION

CSCE 747 Software Testing and Quality Assurance

Race Catcher. Automatically Pinpoints Concurrency Defects in Multi-threaded JVM Applications with 0% False Positives.

Manuel Oriol, CHCRC-C, Software Testing ABB

Reading assignment: Reviews and Inspections

Topics. Software Testing Test Driven Development Black Box Testing Unit Testing White Box Testing Coverage Testing Software Debugging

Chapter 9. Software Testing

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

Object-Oriented Software Engineering Practical Software Development using UML and Java

Software Testing. Testing: Our Experiences

INTRODUCTION TO SOFTWARE ENGINEERING

Verification and Validation. Assuring that a software system meets a user s needs. Verification vs Validation. The V & V Process

Forward Assignment; Strongest Postconditions

Transcription:

T-76.5613 Software Testing and Quality Assurance Lecture 3, 18.9.2006 White-Box Testing Techniques SoberIT

Content What are white-box testing techniques Control flow testing Statement coverage Branch coverage Condition coverage Multicondition coverage How to use white box testing tools Example of one testing tool 2

White-box Testing (structural testing) Testing is based on the knowledge of the inner structure of the software Test cases are designed and selected based on code to exercise specific internal code structures White-box techniques often focus on satisfying a certain test coverage criteria covering all statements, branches, conditions, Different test cases => different execution paths 3

Faults in boolean expressions x && (y z) Perhaps wrongly parenthesized Perhaps should have been && or vice versa Perhaps! was omitted Perhaps the expression was made too complicated Perhaps there are still checks missing Perhaps a wrong variable was used Perhaps short-circuiting was not considered 4

An example 0 + 1 + 2 + + i, i [0, 100] read(i); if ((i < 0) (i > 100)) { error( Input value out of range ); } else { sum=0; x=0; while (x < i) { x=x+1; if (i==10) sum=1; else sum=sum+x; } print(sum); } 5

Test derived using black-box approach i = 1 i = 0 i = 1 i = 50 i = 99 i = 100 i = 101 OK OK OK OK OK OK OK i = 10 Failure! (sum=1) 6

White-box test design techniques Control-flow based coverage criteria Based on the execution order of code statements Statement coverage Decision coverage Condition coverage Decision/condition (multi-condition) coverage Data flow based coverage criteria Based on the values of variables and their flow through the program All definitions testing All uses testing 7

Flow graphs Control-flow graph: a graphical representation of program s internal flow of control Data-flow graph: a graphical representation of program s internal data flow (with respect to some variable); usually an extension of a control-flow graph Flow graphs can be produced automatically Test cases are planned based on the flow graphs Code coverage The relative amount of executed statements during testing Calculated from control-flow or data-flow graph 8

Execution path Execution path is a sequence of nodes (and connecting edges) from the unique begin-node of the flow graph to the unique end-node of the graph. May include same edges and nodes several times (loops) 4 1 2 5 3 6 7 8 9

Statement coverage A set P of execution paths satisfies the statement coverage criterion if and only if for all nodes n in the flow graph, there is at least one path p in P such that p contains the node n. Each program sentence is executed at least once by some test case Satisfies the criterion complete (100%) statement coverage Does not satisfy the criterion partial (<100 %) statement coverage Surprisingly difficult to achieve complete coverage in real life Dead code Error handling code and other rare conditions Inadequate test cases Conditional compiling 10

Statement coverage Percentage of executable statements exercised by a test suite Number of statements exercised/total number of statements Example: Program has 7 statements Tests exercise 6 statements Statement coverage = 85,7% Typical ad hoc testing achieves 60-75% 11

Decision (branch) coverage A set P of execution paths satisfies the branch coverage criterion if and only if for all edges e in the flow graph, there is at least one path p in P such that p contains the edge e. Each control flow branch is executed at least once by some test case Satisfies the criterion complete (100 %) branch coverage Perfect branch coverage perfect statement coverage Usually achieving branch coverage takes more test cases than achieving statement coverage Branch coverage is stronger than statement coverage 12

Decision (branch) coverage Percentage of decision outcomes exercised by a test suite Number of decisions outcomes exercised/total number of decision outcomes Example: Program has 6 branches Tests exercises 3 branches Branch coverage = 50% Statement coverage = 85,7% Typical ad hoc testing achieves 40 60% 13

Statement coverage branch coverage read(i); if ((i < 0) (i > 100)) error(); else { sum=0; x=0; while (x < i) { x=x+1; if (i!= 10) sum=sum+x; } print(sum); } 14

Example read(i) Perfect statement coverage is not always perfect branch coverage Test cases: yes (i<0) (i>100) error() sum=0; x=0 no i=-1 i=1 100% statement coverage no x < i yes x=x+1 Branch Coverage: 5 / 6 = 83,3 % print(sum) no i<>10 yes Test case i=10: sum=sum+x -> sum=0 -> failure 15

Condition Coverage Condition Coverage The internal structure of a structured control predicates is taken into account Both true and false values of each predicate are exercised E.g. (a<0 b>0) -> (true, false) and (false,true) Decision/condition (multi-condition) Coverage The most advanced control-flow testing strategy of practical relevance Execute all sub-predicate boolean value combinations E.g. (a<0 b>0) (true, true), (true, false), (false, true), (false, false) Test each sub-predicate combination separately 16

Strength of structural coverage Branch coverage 100% Coverage criteria Statement coverage 100% Increasing coverage 17

Comparison of white-box methods path coverage all-du-paths stronger independent path c. all-uses all-p / some-c all-c / some-p multicondition condition c. branch c. statement c. all-definitions weaker Note!: Note!: Hierarchy is is just just directing, not not absolute absolute o problem: relationship between between data- data-and and control control flow flow methods (all-p (all-p/ / some-c some-c coverage branch coverage) owhat about about a a program with with no no variables? 18

Choosing the test cases Having chosen a coverage criteria => plan test cases to fulfil the criteria Construct the (control) flow graph for the program Choose the minimum number of execution paths that satisfy the criterion For each selected path, prepare a test case that activates the execution of the path Execute tests Unless coverage achieved, plan more test to add up to the coverage 19

Choosing the inputs Critical sections of code are the control predicates that make execution diverge into different directions p Inputs must be chosen so that when executing the program, correct branch is achieved or the control predicate p gets the aimed boolean values Note! All boolean values are not necessarily possible Often not possible to achieve 100% multi-condition coverage e.g. (i<0 i>100) -> (true, true) combination is not possible 20

Practical Relevance Without a good white-box testing tool analyzing and controlling coverage testing is hopeless. 21

Example: Using coverage tools We used open-source coverage tool EMMA as part of the exercise 1 grading of the last year s course http://emma.sourceforge.net/ Just one tool, plenty of different tools available 22

EMMA coverage tool Coverage metrics that Emma provides Class, method, line, and basic block coverage Basic block is a sequence of bytecode instructions without any jumps or jump targets One line can include more than one basic blocks Cannot measure branches or paths but can detect on bytecode level partially covered lines 23

Example: Coverage of last year unit testing exercise Line (statement) coverage of Assignment 1 Age.java -> 63,7% ~50 LOC AgeComparator.java -> 95,5% ~ 100 LOC Line (statement) coverage of Assignment 2 AgreementChoice.java -> 70,3% ~ 50-100 LOC AgreementChoiceComparator.java -> 80,5% ~ 100-200 LOC 24

Lets see examples of a coverage reports 25

What structural coverage tool can tell us Missing tests Do we need more tests? Weak spots in tests Do we need better tests? Risky areas that are hard to cover Should we try to cover those areas by other type of tests or careful reviews? Unreachable code, old code, debug code Should we remove the dead code? Should we replace the debug code with automated tests? What can we assume if the coverage is high? Only that our tests cover the code concerning the used coverage criteria What can we say about the quality of our tests? 26

Coverage for measuring quality of test cases Coverage tools can be used to control and guide testing Coverage tools highlight non-covered areas of code More tests needed Mainly applicable on unit testing level Missing tests can be identified by reading coverage reports and code Easy to create tests that exercise a specific code block Coverage only shows that the tests exist It does not measure how well the test cases reveal defects Executing,e.g., all code branches does not guarantee that the tests actually show if the branches are incorrect 27

The test coverage trap Functional coverage Function exercised, insufficient structure Better Better testing testing Structure exercised, insufficient function % Statement % Decision Structural coverage % Multicondition 100% 100% coverage does does not not mean mean 100% 100% tested! tested! Structural coverage alone alone does does not not make make good good quality quality tests tests 28

Figure out examples of defects that would not necessarily be detected by coverage based testing 29

Why is structural coverage not enough Missing features Missing code Timing and concurrency issues Different states of the software Astronomical amount of different paths through the software Sequences and order of executing different paths Same path reveals different defects in different states Variations of input conditions Variations of data Qualities Performance, load Security Usability Compatibility, portability Each coverage metric provides a different view to coverage and helps to uncover different things. 30