Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.

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

1 Software Unit Test Coverage And Test Adequacy Hong Zhu, Patrick A. V. Hall, John H.R. May Presented By: Arpita Gandhi.
Unit Testing CS 4311 Hans Van Vliet, Software Engineering, Principles and Practice, 3rd edition, John Wiley & Sons, Chapter 13.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Unit Testing CSSE 376, Software Quality Assurance Rose-Hulman Institute of Technology March 27, 2007.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
Software Testing and Quality Assurance
Testing an individual module
1 Software Testing and Quality Assurance Lecture 5 - Software Testing Techniques.
SOFTWARE TESTING WHITE BOX TESTING 1. GLASS BOX/WHITE BOX TESTING 2.
1 Software Testing Techniques CIS 375 Bruce R. Maxim UM-Dearborn.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Software Systems Verification and Validation Laboratory Assignment 3
System/Software Testing
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
CMSC 345 Fall 2000 Unit Testing. The testing process.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Chapter 13: Implementation Phase 13.3 Good Programming Practice 13.6 Module Test Case Selection 13.7 Black-Box Module-Testing Techniques 13.8 Glass-Box.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
White-Box Testing Techniques II Originals prepared by Stephen M. Thebaut, Ph.D. University of Florida Dataflow Testing.
Coverage – “Systematic” Testing Chapter 20. Dividing the input space for failure search Testing requires selecting inputs to try on the program, but how.
Introduction to Software Testing
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.
CS /51 Illinois Institute of Technology CS487 Software Engineering Software Testing Techniques Mr. David A. Lash.
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.
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
Black-box Testing.
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
CPIS 357 Software Quality & Testing I.Rehab Bahaaddin Ashary Faculty of Computing and Information Technology Information Systems Department Fall 2010.
White-box Testing.
CS 217 Software Verification and Validation Week 7, Summer 2014 Instructor: Dong Si
Coverage Estimating the quality of a test suite. 2 Code Coverage A code coverage model calls out the parts of an implementation that must be exercised.
Testing Techniques Software Testing Module ( ) Dr. Samer Hanna.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
Mutation Testing G. Rothermel. Fault-Based Testing White-box and black-box testing techniques use coverage of code or requirements as a “proxy” for designing.
Software Construction Lecture 19 Software Testing-2.
CS451 Lecture 10: Software Testing Yugi Lee STB #555 (816)
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
1. Black Box Testing  Black box testing is also called functional testing  Black box testing ignores the internal mechanism of a system or component.
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Software Testing. SE, Testing, Hans van Vliet, © Nasty question  Suppose you are being asked to lead the team to test the software that controls.
Defect testing Testing programs to establish the presence of system defects.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
CS223: Software Engineering Lecture 25: Software Testing.
Testing Integral part of the software development process.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Software TestIng White box testing.
Overview Theory of Program Testing Goodenough and Gerhart’s Theory
Software Testing.
White-Box Testing Pfleeger, S. Software Engineering Theory and Practice 2nd Edition. Prentice Hall, Ghezzi, C. et al., Fundamentals of Software Engineering.
Software Testing.
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Software Engineering (CSI 321)
CompSci 230 Software Construction
Structural testing, Path Testing
White-Box Testing Techniques
Types of Testing Visit to more Learning Resources.
White-Box Testing Techniques II
CHAPTER 4 Test Design Techniques
UNIT-4 BLACKBOX AND WHITEBOX TESTING
White-Box Testing Techniques II
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.
White-Box Testing Techniques I
White-Box Testing Techniques II
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Presentation transcript:

Test Coverage CS-300 Fall 2005 Supreeth Venkataraman

CS-300 Fall 2005 Supreeth Venkataraman 2 Test Coverage Coverage is a measure of how much testing can be done given a set of test cases. Given a set of test cases, how much of the code in the program being tested is covered? Or.. Given a set of test cases how many functionalities as listed in the requirements can be tested? Coverage in most cases is a term associated with white-box testing or structural testing.

CS-300 Fall 2005 Supreeth Venkataraman 3 Black Box Testing Black-box testing involves deriving test cases based on the functional requirements of the program being tested. “Does the software exhibit the intended behavior for each of its functionalities?” Black-box testing can be used to detect improper functionality, errors of interface, errors in data structures, and initialization and termination errors with little regard for the logical structure of the program. [Pressman 97]

CS-300 Fall 2005 Supreeth Venkataraman 4 Black Box Testing We have already seen many types of blackbox testing Fault-Based testing, boundary-value testing, etc. Functional testing is thought of as being superior to structural testing in most cases However, it is acknowledged that code based testing does uncover a lot of defects.

CS-300 Fall 2005 Supreeth Venkataraman 5 Equivalence Partitioning A good test case is one that has a good likelihood of uncovering a fault. Exhaustive testing is impossible due to the infinite domain of inputs. We must choose a suitable subset of inputs so that “it covers a large part of other possible test cases” – Myers, p.45

CS-300 Fall 2005 Supreeth Venkataraman 6 Equivalence Partitioning Partition the input domain into equivalence classes The goal here is to partition the inputs in such a way that if one test case in an equivalence class is capable of detecting some fault, then all test cases in that class are capable of detecting the same fault.

CS-300 Fall 2005 Supreeth Venkataraman 7 Equivalence Partitioning An example of an equivalence class for E-LIB. A set of strings that obey the rules of structure of the SSN. While checking for the structure of the SSN, if one test case from our class does not uncover a fault, it is reasonable to assume that none of the strings in the class will reveal a fault.

CS-300 Fall 2005 Supreeth Venkataraman 8 White Box Testing White-box testing is also known as structural testing or code-based testing. The test cases to be used to test the program are derived from the program structure, and not from functional specifications. Many many variations of white-box testing exist.

CS-300 Fall 2005 Supreeth Venkataraman 9 White Box Testing – and criticisms A lot of research has been undertaken to discover the best kind of code coverage. “All testing that does not derive from functions is fundamentally misguided” “People do not use software in order to execute its statements; rather they invoke its functionality”

CS-300 Fall 2005 Supreeth Venkataraman 10 White box or Black box? Achieving code coverage does not imply that good functional coverage is achieved as well. A good mix of functional and structural testing is desirable as both functional as well as code coverage are important. Structural test cases must wait to be derived until the code is written, but functional tests can be derived from requirements. Weyuker proposed that structural testing be used as a way of evaluating functional test quality.

CS-300 Fall 2005 Supreeth Venkataraman 11 White box or Black Box? In many cases, structural coverage is done after adequate functional coverage is achieved. Structural testing is used to back up functional testing If structural testing is inadequate, create additional functional test cases.

CS-300 Fall 2005 Supreeth Venkataraman 12 Test Adequacy The term “adequacy” can be thought of as asking oneself the question “How many test cases do I need in order to completely cover the entire program based on the technique that I have chosen for testing? Or….When do I stop testing?

CS-300 Fall 2005 Supreeth Venkataraman 13 Control Flow Testing Control-flow testing is based on the flow of control in a program. There are many variations of control-flow testing. Statement coverage, branch coverage, path coverage etc. We will examine statement coverage and branch coverage in some detail.

CS-300 Fall 2005 Supreeth Venkataraman 14 The Program Flowgraph A program flowgraph graphically represents the potential control flow of a program. Program flowgraphs are made up of nodes and directed edges Each node represents a basic block, which can be defined as a collection of statements that are always executed together. Each directed edge between two nodes A and B in a control flow graph represents a potential control path from A to B

CS-300 Fall 2005 Supreeth Venkataraman 15 Example Program void myflow(int x,int y) { int a; if (y == 0) { a = 1; } else { a = y; } y = y – 1; if (a > 0) { a = x; } else { a = x + 1; } printf(“%d\n”, a); }

CS-300 Fall 2005 Supreeth Venkataraman y == 0y != 0 a > 0a ≤ 0 1.void myflow(int x, int y) { 2. int a; 3. if (y == 0) { 4. a = 1; 5. } else { 6. a = y; } 7. y = y – 1; 8. if (a > 0) { 9. a = x; 10. } else { 11. a = x + 1; } 12. printf(“%d\n”, a); }

CS-300 Fall 2005 Supreeth Venkataraman 17 Statement Coverage Achieving statement coverage means that all statements in the program have to be executed at least once by a set of test cases Having complete statement coverage does not necessarily mean that the program cannot fail Think about the input space.... Statement coverage is also called all-nodes testing.

CS-300 Fall 2005 Supreeth Venkataraman 18 Statement Coverage Test Cases Test case1: input = {x = 7, y = 0} expected output = {a = 7} Test case2: input = {x = 7, y = -1} expected output = {a = 8}

CS-300 Fall 2005 Supreeth Venkataraman 19 Branch Coverage Achieving branch coverage means that there must be enough test cases so that every path for a conditional transfer of control is exercised Or... Every true and false branch have to be exercised by some test case Complete coverage means that the test cases should be sufficient to traverse all the edges in the program graph. This form of testing is also known as all-edges testing.

CS-300 Fall 2005 Supreeth Venkataraman 20 Branch Coverage The fact that there is complete branch coverage does not mean that all errors will be found. Branch testing does not necessarily check all combinations of control transfers.

CS-300 Fall 2005 Supreeth Venkataraman 21 Branch Coverage Test Cases Test case1: input = {x = 7, y = 0} expected output = {a = 7} Test case2: input = {x = 7, y = -1} expected output = {a = 8}

CS-300 Fall 2005 Supreeth Venkataraman 22 Path Coverage Path coverage means that all possible execution paths in the program must be executed. This is a very strong coverage criterion, but impractical. Programs with loops have an infinite number of execution paths, and thus would need an infinite number of test cases

CS-300 Fall 2005 Supreeth Venkataraman 23 Data Flow Testing Data flow testing is based on the definition and use of variables in a program. Deals with flow of data rather than flow of control. There are many data-flow testing methods All-definitions coverage, all-uses coverage, all- du-paths coverage etc. We will look at all-uses testing in some detail

CS-300 Fall 2005 Supreeth Venkataraman 24 Terminology (Beizer) Definition – a variable is said to be defined when it is initialized with a value as part of a declaration, or when it appears on the left hand side of an assignment statement. eg: x = 4; int y = 0;

CS-300 Fall 2005 Supreeth Venkataraman 25 Terminology Use – The value of a variable is said to be used either when the variable appears on the right hand side of an assignment statement or when it appears in a predicate statement like if (x > y) (Beizer) Eg: y = x;

CS-300 Fall 2005 Supreeth Venkataraman 26 Terminology Definition-clear path - This is a set of connected nodes in the flowgraph where some variable x is defined in the first node, and is not subsequently redefined in any other node in the path. For example, the path is a definition-clear path with respect to variable “x” in figure 2.2.

CS-300 Fall 2005 Supreeth Venkataraman y == 0y != 0 a > 0a ≤ 0 1.void myflow(int x, int y) { 2. int a; 3. if (y == 0) { 4. a = 1; 5. } else { 6. a = y; } 7. y = y – 1; 8. if (a > 0) { 9. a = x; 10. } else { 11. a = x + 1; } 12. printf(“%d\n”, a); }

CS-300 Fall 2005 Supreeth Venkataraman 28 All-Uses Testing The all-uses treatment states that there must be at least one definition-clear path exercised by some test case from every definition of a variable x to all of its uses. All-uses testing is a powerful test coverage criterion.

CS-300 Fall 2005 Supreeth Venkataraman 29 All-Uses test cases Test case1: input = {x = 7, y = 0} expected output = {a = 7} Path = { } Test case2: input = {x = 7, y = -1} expected output = {a = 8} Path = { } Test case3: input = {x = 7, y = 4} expected output = {a = 7} Path = { }

CS-300 Fall 2005 Supreeth Venkataraman 30 The Subsumes Relationship The subsumption relationship means that satisfying one test coverage criterion may implicitly force another test coverage criterion to be satisfied as well Eg: Branch coverage forces statement coverage to be attained as well (This is strict subsumption) “Subsumes” does not necessarily mean “better”

CS-300 Fall 2005 Supreeth Venkataraman 31 Subsumption Hierarchy (Rapps and Weyuker)

CS-300 Fall 2005 Supreeth Venkataraman 32 Mutation Testing Mutation testing involves changing (mutating) the program source statement(s) If the actual output from a test case is different from the expected output (hopefully it will be), the test case is said to kill the mutant. Mutation coverage requires that all mutants be killed

CS-300 Fall 2005 Supreeth Venkataraman 33 Some Mutation Examples Operator mutation – change the operator in the mutated version. Eg: change x + y to x – y or x * y … Change x =y … If all the mutants are killed we are satisfied that no wrong operator has been mistakenly used.

CS-300 Fall 2005 Supreeth Venkataraman 34 Choosing a Testing Method The process If the development process is not well defined without a proper test plan one does not really know what type of testing to apply. If the project starts getting delayed, then testingtime is extremely limited. Resources available testing time, testing experience, budget...

CS-300 Fall 2005 Supreeth Venkataraman 35 Choosing a Testing Method Feasibility Issues Structural testing may not achieve complete code coverage because of dead code Dead code is code that never gets executed. There could be dead statements, dead paths etc. The tester must devote time to identifying infeasible code.

CS-300 Fall 2005 Supreeth Venkataraman 36 Conclusions In practice, there is no agreement as to what the payoffs are for each form of structural testing Functional testing has advantages over structural testing because functional tests capture the expected actions of users.