Code Coverage Metrics And How to Use (and Misuse) Them

Similar documents
Code Coverage Metrics And How to Use Them

Advanced Software Testing Understanding Code Coverage

Advanced Software Testing Testing Code with Static Analysis

Advanced Software Testing Pairwise Testing Techniques

Advanced Software Testing Applying State Diagrams to Business Logic

Non-GUI Test Automation Concepts and Case Studies in Maintainable Testing

Agile Testing in the Real World Moving Beyond Theory to Achieve Practicality [NEED PICTURE HERE]

Advanced Software Testing Integration Testing

Enterprise Challenges of Test Data Size, Change, Complexity, Disparity, and Privacy

Shift Left and Friends And What They Mean for Testers

Analysis for Testing. by: rex Black. quality matters Q3 2009

INTRODUCTION TO SOFTWARE ENGINEERING

Five Hard-Won Lessons In Performance, Load, and Reliability Testing

Can a Mobile Device Save Your Life? Testing, Quality, and Ubiquitous Computing

Darshan Institute of Engineering & Technology for Diploma Studies

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

Defect Classes, the Defect Repository, and Test Design

Certified Tester Foundation Level(CTFL)

Topic: Software Verification, Validation and Testing Software Engineering. Faculty of Computing Universiti Teknologi Malaysia

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

Software Testing Prof. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur. Lecture 13 Path Testing

EXAMINING THE CODE. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist:

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

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Software Engineering Design Principles. Presented by Pratanu Mandal of CSE 3A Roll 54 JISCE

Program Verification! Goals of this Lecture! Words from the Wise! Testing!

Fundamental of Programming (C)

Fundamentals of Programming

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

EECE.2160: ECE Application Programming Spring 2018

Manuel Oriol, CHCRC-C, Software Testing ABB

Program Design: Using the Debugger

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

What is Structural Testing?

Chapter 9. Software Testing

Engineering Quality for Bananas: How One Company Managed Risks and Saved Money with A Dumb Monkey

Literature. CHAPTER 5 Testing. When to Test? The Unified Process. When to Test?

More examples for Control statements

Arithmetic type issues

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

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch

INTRODUCTION TO SOFTWARE ENGINEERING

Master of Computer Application (MCA) Semester III MC0071 Software Engineering 4 Credits

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

c. Typically results in an intractably large set of test cases even for small programs

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

Program Analysis. Program Analysis

Software Testing. Software Testing

10. Software Testing Fundamental Concepts

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

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

PDS: CS Computer Sc & Engg: IIT Kharagpur 1. for Statement

Agile Tester Foundation E-learning Course Outline

FOUR INDEPENDENT TOOLS TO MANAGE COMPLEXITY INHERENT TO DEVELOPING STATE OF THE ART SYSTEMS. DEVELOPER SPECIFIER TESTER

Chapter 15 Debugging

Introduction. Pretest and Posttest Loops. Basic Loop Structures ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

Aerospace Software Engineering

DECISION CONTROL AND LOOPING STATEMENTS

Lecture 26: Testing. Software Engineering ITCS 3155 Fall Dr. Jamie Payton

Subject Software Testing Structural Testing

An Introduction to Systematic Software Testing. Robert France CSU

15 FUNCTIONS IN C 15.1 INTRODUCTION

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

APS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example:

Lecture 10: Recursive Functions. Computer System and programming in C 1

PESIT Bangalore South Campus SOLUTION

Verification and Validation

Introduction. C provides two styles of flow control:

Sample Exam. Advanced Test Automation - Engineer

MACHINE LEARNING BASED METHODOLOGY FOR TESTING OBJECT ORIENTED APPLICATIONS

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops.

MTAT : Software Testing

Programming for Electrical and Computer Engineers. Loops

Unit testing (OHJ-306x)

Objectives. Chapter 19. Verification vs. validation. Topics covered. Static and dynamic verification. The V&V process

Software Testing. Minsoo Ryu. Hanyang University. Real-Time Computing and Communications Lab., Hanyang University

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

Unit 7. Functions. Need of User Defined Functions

Solutions to Assessment

[IT6004-SOFTWARE TESTING] UNIT 2

Introduction to Problem Solving and Programming in Python.

Verification and Validation

Write perfect C code to solve the three problems below.

Chapter 11 Introduction to Programming in C

Lectures 4 and 5 (Julian) Computer Programming: Skills & Concepts (INF-1-CP1) double; float; quadratic equations. Practical 1.

Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not.

Testing Methods: White Box Testing II

Module 4: Decision-making and forming loops

Structural Testing. White Box Testing & Control Flow Analysis

Repetition and Loop Statements Chapter 5

Path Testing + Coverage. Chapter 8

White-Box Testing Techniques

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Programming Embedded Systems

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2013 Midterm I Key

Quality Assurance = Testing? SOFTWARE QUALITY ASSURANCE. Meaning of Quality. How would you define software quality? Common Measures.

Comments. Comments: /* This is a comment */

Transcription:

Code Coverage Metrics And How to Use (and Misuse) Them #include <stdio.h> main() { int i, n, pp, p, c; printf("enter element count: "); scanf("%d", &n); if (n < 0) { printf("no %d series!\n", n); n = -1; } else { printf("{ "); pp = 0; p = 1; for (i=0; i < n; i++) { c = pp + p; printf("%d ", c); pp = p; p = c; } } printf("} \n"); } exit(n);

Cd Code Coverage Mti Metrics Code coverage metrics are tools for measuring the extent of white box test coverage What types of white box coverage apply? Statement, branch, condition, multicondition, multicondition decision, and loop coverage McCabe basis paths Set-use pair (dataflow) coverage Checklist-based test requirements How does white box testing compare to other types of testing? Can tools help with the tedious bits? What bugs does white box testing miss? Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 2

Cd Code Coverage and dwhite Box Testing Dynamic test (compiled, executable) Execute the item under test Create test conditions (e.g., submit inputs) Compare expected and actual results Pure requirements-based tests can miss 80% or more of the code: Do you know which 80% you are not testing? Test design based on how the system works Figure out the control flows Figure out data flows Check against standard checklists or bug taxonomies Code coverage tools monitor the completeness of white box tests and handle the tedious details for you Let s look at these in more detail Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 3

Cd Code-Based d Testing Creating tests to achieve levels of coverage Statement coverage: every statement executed Branch coverage: every branch (decision) taken each way, true and false Condition coverage: every condition evaluated once true and once false Multicondition coverage: for compound conditions, every possible combination of constituent conditions covered Multicondition decision coverage: for compound conditions, every possible combination of constituent conditions that can affect the decision i covered Loop coverage: Ideally all possible loop paths taken, but usually loop paths taken zero, once, and multiple (ideally, maximum) times Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 4

Cd Code Coverage Example What test values for n do we need to cover all the statements? n < 0, n > 0 Does that get us branch coverage? No, need to add n = 0 Does that get us condition coverage? Yes: no compound conditions How about loop coverage? Need to cover n = 1 and n = max 1 main() 2 { 3 int i, n, pp, p, c; 4 printf("enter element count: "); 5 scanf("%d", &n); 6 if (n < 0) { 7 printf("no %d series!\n", n); 8 n = -1; 9 } else { 10 printf("{ "); 11 pp = 0; 12 p = 1; 13 for (i=0; i < n; i++) { 14 c = pp + p; 15 printf("%d ", c); 16 pp = p; 17 p = c; 18 } 19 printf("} \n"); 20 } 21 exit(n); 22 } Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 5

Variations on Condition Coverage So, when do condition coverage, multicondition 1 if (( 0) (b )) { coverage, and multicondition decision coverage vary? 5 } How many tests for each type of coverage for lines 1-5? 9 } else { How about for lines 7-11? 11 } Does multicondition coverage 12 \ even make sense for lines 7-11? Let s compare the testing for lines 1-5 with lines 13-17 17 1 if ((a>0) && (b>a)) { 2 printf( Success.\n ); 3 } else { 4 printf( Failure.\n ); 6 7 if ((f!=null) && (*f==0)) { 8 printf( Found.\n ); 10 printf( Not found.\n ); 13 if ((a<=0) (b<=a)) { 14 printf( Failure Failure.\n \n ); 15 } else { 16 printf( Success.\n ); 17 } Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 6

MC McCabe Cyclomatic Complexity McCabe s Cyclomatic Complexity measures control flow complexity Measured by drawing a directed graph Nodes represent entries, exits, decisions Edges represent non-branching statements It has some useful testing implications High-complexity modules are inherently buggy and regression-prone The number of basis paths through the graph is equal to the number of basis tests to cover the graph Let s see how Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 7

Cyclomatic Complexity for Fibonacci i Cyclomatic Complexity C = #Regions + 1 = 2 + 1 = 3 C = #Edges - #Nodes +2 = 5-4 +2 = 3 Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 8

Basis Paths and dtests Basis Paths 1. 124 2. 1234 3. 12334 Basis Tests 1. n = -1 2. n = 0 3. n = 1 Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 9

Analyzing Data Flow Set-Use Pairs So far, we ve focused on testing control flows How about testing data flows? We can analyze data flows using set-use pair coverage Do we cover every variable set-and- subsequent-use (assigning the variable a value, then using that variable, but before assigning g the variable again)? Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 10

Dt Data Flow Coverage Example i: (13,13) n=0 covers assign-use n=1 covers increment-use n: (5,6), (5,13), (5,21), (8,21) n=-1 covers (5,6), (8,21) n=0 adds (5,13), (5,21) pp: (11,14),(16,14) n=1 covers (11,14) n=max adds (16,14) p: (12,14), (12,16), (17,14) n=1 covers (12,14) n=max adds (12,16), (17,14) c: (14,15), 15) (14,17) 17) n=1 covers (14,15) n=max adds (14,17) Basis cover!= data-flow cover For c into p into pp into c, iterate loop three times 1 main() 2 { 3 int i, n, pp, p, c; 4 printf("enter element count: "); 5 scanf("%d", &n); 6 if (n < 0) { 7 printf("no %d series!\n", n); 8 n = -1; 9 } else { 10 printf("{ "); 11 pp = 0; 12 p = 1; 13 for (i=0; i < n; i++) { 14 c = pp + p; 15 printf("%d ", c); 16 pp = p; 17 p = c; 18 } 19 printf("} \n"); 20 } 21 exit(n); 22 } Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 11

Checklist-based Test Requirements Tests can be designed based on a catalog of test requirements, a bug taxonomy or other checklists of important aspects to be tested Frequent program operations combined with typical buggy aspects of those operations make a good catalog of test requirements Select test requirements; cover with tests Let s test Fibonacci with Brian Marick s catalog, from The Craft of Software Testing Click here to see the test requirements catalog, from Marick s book Click here to see the tests developed using the test requirements catalog Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 12

AB Basic Catalog-Based Test Design Process Review requirements, design, code, and data structures Compare each element to checklist or catalog Accumulate clues and test requirements Design tests to cover the test requirements Avoid covering multiple error-related test requirements in one test where possible Seek as much test variety as possible Run tests Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 13

Comparing Techniques Static White box Black box What Test without running Test how system works Test what system does Why Identify bugs before Identify bugs in Identify bugs in system they re built functions or interfaces results and behavior Who All stakeholders Typically developers Typically testers Phase During specification Usually unit, Usually integration, and development component, integrationi system, and acceptance Tools Simulators, code analyzers, spell- and grammar checkers, graphic/diagramming, spreadsheets Profilers, coverage analyzers, harnesses, db debuggers, data generators, test case generators Intrusive and nonintrusive GUI tools, load generators, performance tools, data generators Tools, data, and cases can be shared: encourage cross-pollination of techniques Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 14

What a Tedious Chore! Trying to measure metrics like controlflow coverage and Cyclomatic Complexity is not a fun pastime Fortunately, there are tools that can help It s harder to find data-flow coverage tools Anyone have a test catalog coverage tool? Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 15

What Can t White Box Tests Find? As essential as it is to have well-tested units and builds, white box testing can t find every kind of bug Bugs of omission Missing requirements, design elements, code Use requirements, design and code reviews Unmaintainable code Inscrutable variable names or constructs, etc. (though McCabe complexity helps) Use code reviews and static analysis tools Systemic problems Performance, security, usability, interoperability, etc. Use code reviews, black-box system testing, beta/pilot tests, usability studies, prototyping, etc. Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 16

Conclusions White box testing is dynamic testing (running item under test) based on knowledge of how it works There are four main theoretical techniques Statement, branch, condition, and loop coverage Basis paths Set-use pair (dataflow) coverage Test requirements catalogs Tools are very helpful in measuring the coverage of white box tests White box testing is complementary to black box testing static testing Use all three to form a complete testing strategy Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 17

Contact trbcs For over a dozen years, RBCS has delivered services in consulting, outsourcing and training for software and hardware testing. Employing the industry s s most experienced and recognized consultants, RBCS conducts product testing, builds and improves testing groups and hires testing staff for hundreds of clients worldwide. Ranging g from Fortune 20 companies to start-ups, RBCS clients save time and money through improved product development, decreased tech support calls, improved corporate reputation and more. To learn more about RBCS, visit www.rbcs-us.com. Address: RBCS, Inc. 31520 Beck Road Bulverde, TX 78163-3911 USA Phone: +1 (830) 438-4830 Fax: +1 (830) 438-4831 E-mail: info@rbcs-us.com Wb Web: www.rbcs-us.com Code Coverage Metrics Copyright (c) 2004-2009 RBCS Page 18