CompSci 230 Software Construction

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

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.
Introduction to Software Engineering Lecture 11 André van der Hoek.
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. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
CompSci 230 Software Design and Construction
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
System/Software Testing
CMSC 345 Fall 2000 Unit Testing. The testing process.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
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.
Testing Vs. Inspection Research Paper Diala T. Gammoh, Ph.D. Student Dr. Damla Turgut, Ph.D. University of Central Florida, Orlando Florida
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
Software Construction Lecture 18 Software Testing.
White-box Testing.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Testing software Team Software Development Project.
Software Construction Lecture 19 Software Testing-2.
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 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Testing (final thoughts). equals() and hashCode() Important when using Hash-based containers class Duration { public final int min; public final int sec;
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.
Testing Integral part of the software development process.
A Review of Software Testing - P. David Coward
Software TestIng White box testing.
Overview Theory of Program Testing Goodenough and Gerhart’s Theory
Testing Verification and the Joy of Breaking Code
Testing Tutorial 7.
Software Testing.
Software Testing.
Control Flow Testing Handouts
John D. McGregor Session 9 Testing Vocabulary
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
The Joy of Breaking Code Testing Logic and Case Selection
Software Testing and Maintenance 1
Chapter 8 – Software Testing
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Software engineering – 1
Some Simple Definitions for Testing
Structural testing, Path Testing
White-Box Testing Techniques
Types of Testing Visit to more Learning Resources.
John D. McGregor Session 9 Testing Vocabulary
CHAPTER 4 Test Design Techniques
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Introduction to Software Testing Chapter 2 Model-Driven Test Design
John D. McGregor Session 9 Testing Vocabulary
Testing, conclusion Based on material by Michael Ernst, University of Washington.
Software Testing (Lecture 11-a)
Lecture 09:Software Testing
Testing and Test-Driven Development CSC 4700 Software Engineering
Verification and Validation
Software testing.
CS240: Advanced Programming Concepts
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.
Basics of Recursion Programming with Recursion
CSE403 Software Engineering Autumn 2000 More Testing
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Chapter 7 Software Testing.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing.
Presentation transcript:

CompSci 230 Software Construction Lecture Slides #24: White Box testing S1 2016

Agenda Topics: White box testing General considerations Choosing test cases for white box testing Statement coverage Branch coverage Path coverage Condition coverage White box testers Myers’ principles for testing CompSci 230: WB

White Box Testing – general considerations Design tests based on implementation itself (structure of code) When we design tests, we have access to the source code and use it to derive our test design We try to design tests that ensure that the execution always runs correctly, but how do we do that? Usefulness of testing vs. effort is an issue in white box testing, too CompSci 230: WB

Concept: Control flow graphs (CFG) Each statement in the IUT is a node (vertex) If execution can move from node u to node v, we connect u and v via an arc (branch) public void deleteCurrencyByCode(String code) { if (currencies == null) return; for (int i=0; i < currencies.length; i++) { if (currencies[i].getCode().equals(code)) { if (currencies.length == 1) { currencies = null; return; } else { Currency[] tmpCurrencies = new Currency[currencies.length-1]; for (int j=0; j<i; j++) { tmpCurrencies[j] = currencies[j]; for (int j=i; j<tmpCurrencies.length; j++) { tmpCurrencies[j] = currencies[j+1]; currencies = tmpCurrencies; CompSci 230: WB

Statement coverage When a test executes a particular statement (vertex) in the CFG, we say that it covers this statement A test suite whose tests cover a (sub)set of statements in the IUT is said to have (partial/complete) statement coverage Advantage: number of statement in IUT is finite Problem: it may be difficult to design tests that reach every statement (e.g., consider a method that always returns before it reaches the last statements) But then this is a defect and may be detected that way! Can you think of a situation in which a test suite with complete statement coverage might not expose a fault in the IUT? CompSci 230: WB

Branch coverage Another approach is to design a test suite so that for every arc in the CFG, there is at least one test in which the execution follows that branch For this purpose, we may work with a simplified CFG where we remove nodes with one incoming and one outgoing branch only Can you think of a case where branch coverage is not possible? Can you think of a case where a test suite providing branch coverage could fail to expose a fault? CompSci 230: WB

Path coverage Can work from simplified CFG here Each possible execution sequence of nodes in the CFG is a path Idea: Test all possible paths in the IUT Problem: The number of paths may be infinite (e.g., our example, it is) Usually, this is because of loops in the CFG Some paths may infeasible under actual execution E.g., consider two successive if-else statements with the same condition whose variables don’t change. Then the first if-branch followed by the second else-branch is an infeasible path Challenge: find a test set of paths that is most likely to trigger a failure CompSci 230: WB

Condition coverage Consider a fault in an if-statement: Statement should be: if (a > 0 AND b > 0) {… Actual statement: if (a > 0 OR b > 0) {… Testing with (a=0, b=0) and (a=1,b=1) gives statement, branch, and path coverage for the if-statement Fault remains undetected Condition coverage aims to find test cases such that each clause (such as “a > 0” or “b==7”) in an if-statement’s condition will become true and false, in every possible combination. Problem: Potentially large number of combinations, not every combination is feasible Compromise: Try and find test cases where the change in truth value of a clause causes the entire condition to change its truth value E.g., (a > 0 AND (b > 0 OR c < 0)): If b > 0, value of c does not matter, value of a determines the overall value of the condition. Similarly, if c < 0, the value of b does not matter. CompSci 230: WB

White box testing – general considerations Black box testing more or less forces us to look at the specifications: What is that thing supposed to do? White box testing puts the focus on deriving test cases from the code structure of the IUT as it was implemented But what if that structure doesn’t just contain faults, but is in itself faulty? E.g., missing code, such as an if-statement that needs an else branch E.g., developer misunderstood specifications What question does this raise? Need to go back to the specifications to design good test cases! CompSci 230: WB

The ideal white box tester Must-have: Knows the programming language that the IUT is written in Knows and understands the specifications perfectly Was not involved in the thought processes that led to the implementation (carries no preconception as to how the problem ought to be solved, or is biased by how it was solved) So ideally, the tester will not be the developer CompSci 230: WB

Myer’s Principles for Testing A necessary part of a test case is a definition of the expected output or result A programmer should avoid attempting to test his or her own program A programming organization should not test its own programs Thoroughly inspect the results of each test Test cases must be written for input conditions that are invalid and unexpected, as well as for those that are valid and expected Examining a program to see if it does not do what it is supposed to do is only half the battle; the other half is seeing whether the program does what it is not supposed to do Avoid throwaway test cases unless the program is truly a throwaway program Do not plan a testing effort under the tacit assumption that no errors will be found The probability of the existence of more errors in a section of a program is proportional to the number of errors already found in that section Testing is an extremely creative and intellectually challenging task CompSci 230: WB

Example Principle 4: Thoroughly inspect the results of each test Test case input for the method: an identifier for an album in the database Expected return: A list of song titles on the album with their durations in minutes and seconds Get: Sweet love in the rainy sunshine 3:12 Ginger on my mind 4:42 Oh come on (Remix) 3:65 Platitudes for platypus 3:52 Ginger on my mind (Remix) 4:20 Looks like a pass, but is it? Any other principles at stake here? CompSci 230: WB

Review Is it harder to be a black box tester or a white box tester? Can you explain the difference between statement coverage, branch coverage, path coverage and condition coverage in a paragraph or two? Which of statement coverage, branch coverage, path coverage and condition coverage can we usually achieve (if we don’t mind the effort)? Which challenges do we face in white box testing? Name three consequences of following Myers’ principles Do Myers principles guarantee that testing will result in fault-free software? CompSci 230: WB