Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University

Slides:



Advertisements
Similar presentations
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Advertisements

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.
Black box testing  Black box tests focus on the input/output behavior of the component  Black-box tests do not deal with the internal aspects of the.
Software testing.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Software Testing and Quality Assurance
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing 2.
Testing an individual module
Chapter 18 Testing Conventional Applications
1 Software Testing Techniques CIS 375 Bruce R. Maxim UM-Dearborn.
1 Joe Meehean. 2 Testing is the process of executing a program with the intent of finding errors. -Glenford Myers.
CSE 403 Lecture 13 Black/White-Box Testing Reading: Software Testing: Principles and Practices, Ch. 3-4 (Desikan, Ramesh) slides created by Marty Stepp.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
System/Software Testing
White-box Testing Black-box Testing Extensions
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Testing phases. Test data Inputs which have been devised to test the system Test cases Inputs to test the system and the predicted outputs from these.
Software testing techniques 3. Software testing
Prof. Mohamed Batouche Software Testing.
9/18/2015CPSC , CPSC , Lecture 121 Software Engineering, CPSC , CPSC , Lecture 12.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Software Engineering Chapter 23 Software Testing Ku-Yaw Chang Assistant Professor Department of Computer Science and Information.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
CSC 480 Software Engineering Lecture 14 Oct 16, 2002.
Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke.
Course Outline Traditional Static Program Analysis –Theory –Classic analysis and applications Points-to analysis, CHA, RTA –The Soot analysis framework.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 23 Slide 1 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.
Software Testing The process of operating a system or component under specified conditions, observing and recording the results, and making an evaluation.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 1 W. Eric Wong Department.
Agenda Introduction Overview of White-box testing Basis path testing
Neil Ghani Software testing. 2 Introduction In a perfect world all programs fully verified testing thus redundant Back in the real.
CS451 – Software Testing Technologies Blackbox Testing Equivalence Partitioning.
INF 111 / CSE 121: Software Tools and Methods Lecture Notes for Fall Quarter, 2007 Michele Rousseau Set 12 (Some slides adapted from Sommerville 2000 &
CSE403 Software Engineering Autumn 2001 More Testing Gary Kimura Lecture #10 October 22, 2001.
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 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.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Software Testing Yonsei University 2 nd Semester, 2014 Woo-Cheol Kim.
Black-box Testing.
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
CS 217 Software Verification and Validation Week 7, Summer 2014 Instructor: Dong Si
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
Test Case Designing UNIT - 2. Topics Test Requirement Analysis (example) Test Case Designing (sample discussion) Test Data Preparation (example) Test.
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.
Condition Testing. Condition testing is a test case design method that exercises the logical conditions contained in a program module. A simple condition.
Theory and Practice of Software Testing Chapter 14 Presman Software Testing Tactics BLACK BOX TESTING.
1 © 2011 Professor W. Eric Wong, The University of Texas at Dallas Requirements-based Test Generation for Functional Testing W. Eric Wong Department of.
Week 6 MondayTuesdayWednesdayThursdayFriday Testing III Reading due Group meetings Testing IVSection ZFR due ZFR demos Progress report due Readings out.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
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.
Dynamic Black-Box Testing Part 1 What is dynamic black-box testing? How to reduce the number of test cases using: Equivalence partitioning Boundary value.
Testing Data Structures
Software Testing.
Input Space Partition Testing CS 4501 / 6501 Software Testing
Types of Testing Visit to more Learning Resources.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 14 Software Testing Techniques
Software testing.
Software Testing “If you can’t test it, you can’t design it”
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Presentation transcript:

Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University

Objectives Master practical testing techniques use similar techniques to test students' own code at hand handle programming interview questions related to testing Master systematic testing techniques apply both black-box and white-box testing techniques effectively use the JUnit framework and code-coverage tool

Testing Setup = ? public class BST { void insert(int v) { … } void remove(int v) { … }... } t.size(): 1 t.contain(2): false t.size(): 1 t.contain(2): false Outputs Expected Outputs Program Test inputs Test 1 void test1() { BST t = new BST (); t.insert(2); t.size(); t.remove(2); t.contain(2); }

How is it different to test LinkedList than Anagram? Testing LinkedList Test a LinkedList’s get(int X), which returns the element at the specified position in this list. Testing Anagram Test a method which checks whether two words are anagrams of each other Test a method which checks to see if a word has any anagrams in a dictionary of words

How is it different to test LinkedList than Anagram? Testing LinkedList Test a LinkedList’s get(int X), which returns the element at the specified position in this list. A data structure has object states Method Execution receiver-object arguments method return Input =+ Output = + receiver-object

How is it different to test LinkedList than Anagram? Testing LinkedList Test a LinkedList’s get(int X), which returns the element at the specified position in this list. A data structure has object states Implicit input for a method besides arguments How to prepare object states? e.g. a LinkedList with size 5 What object states to prepare? Implicit output for a method besides return How to check object states?

Classic Unit Test Construction public void testLinkedListXXX { Construct the object state under test (OUT) Optionally save the state of the OUT Call the method under test (MUT) if an exception was generated Test for unhandled exceptions else Assertions on the return, OUT, and arguments }

LinkedList add Example How to know we get an expected new LinkedList object after calling add(5) on a LinkedList object (containing 1 and 5)? public testLinkedListAdd3 () { LinkedList s = new LinkedList(); s.add(1); s.add(5);//s is now prepared as OUT s.add(5);//MUT assertTrue(?????);... assertTrue(?????); } Backup/regenerate OUT LinedList b = s.clone(); LinedList b= new LinkedList(); b.add(1); b.add(5); OR

Asserting Object States How to know we get an expected new LinkedList object after calling add(5) on a LinkedList object (containing 1 and 5)? Invoke other non-void-return methods (observers) on the new object, e.g., assertTrue(s.contains(5)), assertTrue(s.getLast()==5), assertTrue(s.size()==3). Invoke toString() on the new object, e.g., assertTrue(s.toString().equals(“1,5,5”)) Invoke equals() on the new object, e.g., assertTrue(!s.equals(…)). When we call s.add(5) and s.removeLast(5) on an object state S, we want to check the new object is equal to S. Need backup/clone S or regenerate S

Testing Techniques Black-box testing Equivalence Partitioning Testing Boundary Value Testing White-box testing Statement coverage = ? public class BST { void insert(int v) { … } void remove(int v) { … }... } t.size(): 1 t.contain(2): false t.size(): 1 t.contain(2): false Outputs program void test99() { BST t = new BST (); t.insert(2); t.size(); } test inputs Expected Outputs

Consider a method findMax that is supposed to find the max element in a LinkedList: We test the method on the following inputs and observe the outputs as shown: Can we claim that the method is correct ? Example From Diane Horton’s handout

Example It seems these 10 test cases are good enough; but in fact, they are not well chosen We can easily construct a method that passes these then cases but fails in: A very short list (i.e., of length 1, 2, or 3) An empty list (i.e., of length 0) In fact, easy to forget to specify the method’s behavior for this type of “boundary” case A list where the max elem is the first or last element. A list where the max elem is negative In fact, all 10 tests cover essentially the same situation A list of moderate length, all positive integers, the max elem is somewhere in the middle From Diane Horton’s handout

Equivalence Partitioning Input domain is usually too large for exhaustive testing. Partition input domain into a finite number of sub- domains for the selection of test inputs. Each sub-domain is known as an equivalence class and serves as a source of at least one test input. Input domain partitioned into four sub-domains. Too many test inputs. Four test inputs, one selected from each sub- domain.

How to partition? Inputs to a program provide clues to partitioning. Example: given a LinkedList with size 10, get(int X) returns the element at the specified position in this list. Prohibitively large input domain: X can assume a large number of values. Which index X shall we test?

How to partition? Example: given a LinkedList with size 10, get(int X) returns the element at the specified position in this list. We expect LinkedList to behave the same way for all X<0 behave the same way for all X>9 behave the similar way for all 0<=X<=9 Partition the input domain of P into three sub- domains.

How to partition? All test inputs in the X<0 sub-domain are considered equivalent. The assumption is that if one test input in this sub-domain reveals an error in the program, so will the others. This is true of the test inputs in the X>9 sub-domain or the 0<=X<=9 sub-domain too. Then we selected just enough tests to cover each partition. One test case: X=-3 Another test case: X=15 X<0 X>9 0<=X<=9 Another test case: X=5 Equivalence class

Guideline for Partitioning Input condition specifies a range: create one for the valid case and two for the invalid cases. e.g., for a<=X<=b the classes are a<=X<=b (valid case) X b (the invalid cases) Input condition specifies a value: create one for the valid value and two for incorrect values (below and above the valid value). This may not be possible for certain data types, e.g., for boolean. Input condition specifies a member of a set: create one for the valid value and one for the invalid (not in the set) value. e.g., contains(Object o)

Boundary Value Testing Faults tend to be concentrated at edges of input domain – look for boundary values as test inputs One test case: X=-3 Another test case: X=15 X<0 X>9 Equivalence class 0<=X<=9 Another test case: X=5 X=0 and X=9 are boundaries. Inputs to the program might lie on the boundary or on either side of the boundary. Lie on boundary: 0, 9 Lie on valid side of the boundary: 1, 8 Lie on Invalid boundary cases: -1, 10 Equivalence class

Testing Arbitrary LinkedList Example: given a LinkedList with size 10, get(int X) returns the element at the specified position in this list. Input condition ? 0<=X<=9 Input: X

Testing Arbitrary LinkedList Example: given a LinkedList with size 10, get(int X) returns the element at the specified position in this list. s.size()>=0 0<=X<= s.size()-1 Input: X Input condition 0<=X<=9 Inputs: X, S Input conditions What tests to generate?

Another example Example: given a LinkedList, contains(Object e) returns true if this list contains the specified element. Input conditions ? Inputs: e, S

Another example Example: given a LinkedList, contains(Object e) returns true if this list contains the specified element. Input condition LinkedList s of size n s.size()>=0 e not in s e in s (e’s position) Adapted from Norman Fenton’s slide Input conditions Inputs: e, S

How many tests shall be generated? Example: given a LinkedList, contains(Object e) returns true if this list contains the specified element. Input condition LinkedList s of size n s.size()>=0 e not in s e in s (e’s position) Adapted from Norman Fenton’s slide Input conditions Inputs: e, S

How many tests shall be generated? Example: given a LinkedList, remove(Object e) returns true if this list contains the specified element. Input condition LinkedList s of size n s.size()>=0 e not in s e in s (e’s position) Adapted from Norman Fenton’s slide Input conditions Inputs: e, S

findMax example revisited Consider a method findMax that is supposed to find the max element in a LinkedList We can easily construct a method that passes these then cases but fails in: 1. A very short list (i.e., of length 1, 2, or 3) 2. An empty list (i.e., of length 0) In fact, easy to forget to specify the method’s behavior for this type of “boundary” case 3. A list where the max elem is the first or last element. 4. A list where the max elem is negative How can we generate these tests using the techniques we just learned? what test conditions?  what tests?

findMax example revisited Consider a method findMax that is supposed to find the max element in a LinkedList We can easily construct a method that passes these then cases but fails in: 1. A very short list (i.e., of length 1, 2, or 3) 2. An empty list (i.e., of length 0) In fact, easy to forget to specify the method’s behavior for this type of “boundary” case 3. A list where the max elem is the first or last element. 4. A list where the max elem is negative Input: s Input conditions: s.size()>=0, 0<=max’s position<s.size() MIN < max’s value < MAX

White-Box Testing Determining test cases from a knowledge of the internal logic of the software Four main types of white-box testing Statement Testing Loop Testing Path Testing Branch Testing

White-Box Testing Statement Testing: Test single statements Loop Testing: Cause execution of the loop to be skipped completely. (Exception: Repeat loops) Loop to be executed exactly once Loop to be executed more than once Path testing: Make sure all paths in the program are executed Branch Testing (Conditional Testing): Make sure that each possible outcome from a condition is tested at least once if (i == true) System.out.println("YES"); else System.out.println("NO"); Test cases: 1) i = true; 2) i = false

White-Box Testing Statement Testing: Test single statements Loop Testing: Cause execution of the loop to be skipped completely. (Exception: Repeat loops) Loop to be executed exactly once Loop to be executed more than once Path testing: Make sure all paths in the program are executed Branch Testing (Conditional Testing): Make sure that each possible outcome from a condition is tested at least once if (i == true) System.out.println("YES"); System.out.println("OK"); Test cases: 1) i = true; 2) i = false

Coverage Measurement Tool Measure statement coverage Know which statements haven’t been exercised Then you can try to generate tests to exercise them A challenging problem though for complex programs

Both black-box and white-box testing are needed From Norman Fenton’s slide