Testing Data Structures

Slides:



Advertisements
Similar presentations
Chapter 14 Software Testing Techniques - Testing fundamentals - White-box testing - Black-box testing - Object-oriented testing methods (Source: Pressman,
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.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
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 and Quality Assurance
Testing an individual module
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.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
System/Software Testing
Com1040 Systems Design and Testing Part II – Testing (Based on A.J. Cowling’s lecture notes) LN-Test3: Equivalence classes and boundary conditions Marian.
CMSC 345 Fall 2000 Unit Testing. The testing process.
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.
CSC 480 Software Engineering Lecture 14 Oct 16, 2002.
Course Outline Traditional Static Program Analysis –Theory –Classic analysis and applications Points-to analysis, CHA, RTA –The Soot analysis framework.
Agenda Introduction Overview of White-box testing Basis path testing
CS451 – Software Testing Technologies Blackbox Testing Equivalence Partitioning.
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.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
(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.
Test Case Designing UNIT - 2. Topics Test Requirement Analysis (example) Test Case Designing (sample discussion) Test Data Preparation (example) Test.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University
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.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
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.
Equivalence Partitioning
Functional testing, Equivalence class testing
Software Engineering (CSI 321)
Equivalence partitioning
Equivalence partitioning
Testing Tutorial 7.
Software Testing.
Software Testing.
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
The Joy of Breaking Code Testing Logic and Case Selection
Black Box Testing PPT Sources: Code Complete, 2nd Ed., Steve McConnell
Software Engineering (CSI 321)
IS301 – Software Engineering V:
Input Space Partition Testing CS 4501 / 6501 Software Testing
Testing & Testing Tools
Structural testing, Path Testing
Types of Testing Visit to more Learning Resources.
Testing Approaches.
Requirements-Based Testing
Testing UW CSE 160 Spring 2018.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing (Lecture 11-a)
Chapter 14 Software Testing Techniques
Software testing.
CSE 403 Lecture 13 Black/White-Box Testing Reading:
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
CSE403 Software Engineering Autumn 2000 More Testing
Institute of Computing Tech.
Black-Box Testing Techniques III
Software Testing “If you can’t test it, you can’t design it”
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing.
Presentation transcript:

Testing Data Structures CSE 373 Tao Xie Dept. of Computer Science and Engineering University of Washington, Seattle

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 ? Test inputs Program Expected Outputs Outputs Test 1 void test1() { BST t = new BST (); t.insert(2); t.size(); t.remove(2); t.contain(2); } 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

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 Input = receiver-object state@entry + method arguments Method Execution Output = receiver-object state@exit + method return

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(?????); ... } Backup/regenerate OUT LinedList b = s.clone(); OR LinedList b= new LinkedList(); b.add(1); b.add(5);

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 White-box testing ? Equivalence Partitioning Testing Boundary Value Testing White-box testing Statement coverage program test inputs Outputs Expected Outputs = ? void test99() { BST t = new BST (); t.insert(2); t.size(); } 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

From Diane Horton’s handout Example 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 ? From Diane Horton’s handout

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. 1 2 3 4 Input domain Too many test inputs. Four test inputs, one selected from each sub-domain.

Which index X shall we test? 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? One test case: X=-3 Equivalence class X>9 Another test case: X=15 X<0 Another test case: X=5 0<=X<=9 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. The rationale of our new approach for defining redundant tests is to focus on each method execution individually and consider that it is unnecessary to … In other words, we assume the code under test is single-threaded. To support testing multithreading programs, we need to focus on execution entities with a finer granularity than method executions. We leave this to our future work.

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<a and 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 Errors tend to be concentrated at edges of input domain – look for boundary values as test inputs One test case: X=-3 Equivalence class X>9 Another test case: X=15 X<0 Another test case: X=5 0<=X<=9 Equivalence class 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

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

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

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

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

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

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

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: 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 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: 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 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

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

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