The Joy of Breaking Code Testing Logic and Case Selection

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 17 Software Testing Techniques
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Testing an individual module
Chapter 18 Testing Conventional Applications
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Software Engineering Lecture 12 Software Testing Techniques 1.
Chapter 13 & 14 Software Testing Strategies and Techniques
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
System/Software Testing
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
CMSC 345 Fall 2000 Unit Testing. The testing process.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Agenda Introduction Overview of White-box testing Basis path testing
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
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.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 14a: Software Testing Techniques Software Engineering: A Practitioner’s Approach, 6/e Chapter.
Today’s Agenda  Reminder: HW #1 Due next class  Quick Review  Input Space Partitioning Software Testing and Maintenance 1.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Testing and inspecting to ensure high quality An extreme and easily understood kind of failure is an outright crash. However, any violation of requirements.
Testing Data Structures Tao Xie Visiting Professor, Peking University Associate Professor, North Carolina State University
Dynamic Testing.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.1.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Software Testing Testing is the process of exercising a program with the specific intent of finding errors prior to delivery to the end user.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
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
Functional testing, Equivalence class testing
Chapter 17 Software Testing Techniques
Software Testing CS II: Data Structures & Abstraction
Chapter 18 Testing Conventional Applications
Testing Verification and the Joy of Breaking Code
Testing Tutorial 7.
Black Box Testing PPT Sources: Code Complete, 2nd Ed., Steve McConnell
Software Testing Techniques
CompSci 230 Software Construction
Testing and Debugging.
CS5123 Software Validation and Quality Assurance
Chapter 18 Testing Conventional Applications
Software Engineering: A Practitioner’s Approach, 6/e Chapter 13 Software Testing Strategies copyright © 1996, 2001, 2005 R.S. Pressman & Associates,
Chapter 13 & 14 Software Testing Strategies and Techniques
Testing the Software with Blinders on
Types of Testing Visit to more Learning Resources.
Testing UW CSE 160 Spring 2018.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Chapter 18 Testing Conventional Applications
Chapter 18 Testing Conventional Applications
Static Testing Static testing refers to testing that takes place without Execution - examining and reviewing it. Dynamic Testing Dynamic testing is what.
CSE 403 Lecture 13 Black/White-Box Testing Reading:
Chapter 18 Testing Conventional Applications
Chapter 10 – Software Testing
Chapter 23 Testing Conventional Applications
CSE403 Software Engineering Autumn 2000 More Testing
Black-Box Testing Techniques III
Objectives You should be able to describe: The while Statement
CSE 1020:Software Development
Automated test.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 1: Creating a Program.
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

The Joy of Breaking Code Testing Logic and Case Selection SENG 301

Learning Objectives By the end of this lecture, you should be able to identify, understand and use: Equivalence-based strategies for selecting test cases Boundary-based strategies for selecting test cases Path-based strategies for selecting test cases State-based strategies for selecting test cases

On #in-class Imagine you were trying to test this function signature. Post a test case (or a set of test cases) along with the expected result, and explain why you would test what you would. /** Returns the string for the date: e.g. Monday, 18 Oct * @param month 1-12 * @param dayOfWeek 1-7 * @param day 1-31 * @throws OutOfRangeException */ string dateString(int dayOfWeek, int day, int month) {…}

Some Test Cases

Recall Exhaustive (or brute force) testing is likely infeasible We need to select a practical handful of tests to run, because some of these take a lot of time!

Testing Strategies (a subset) Black-box Equivalence-based selection Boundary-based selection White-box Path-based selection State-based selection

Strategy: Equivalence-based Selection Insight: While functions may accept a wide range of inputs, it will treat “groups” of inputs in similar ways Idea: Test only one member of each of these groups Group all possible inputs into sets for which the output is identical or “similar”  i.e. partition input into “equivalence classes” For each equivalence class, test one representative member (and we assume that behaviour of other members is identical) NB: Sometimes, it’s tricky to figure out what the “right” equivalence classes are

Example /** Returns the “school type” (e.g. pre-school, primary school, elementary school, secondary school) depending on student’s age at the beginning of the school year */ string SchoolTypeForAge(double age); Five equivalence classes: pre-school kids (2-4y) primary-school age (5-8y) elementary-school age (9-14y) secondary-school age (15-17y) outside-of-range (<2, >18)

#in-class How many equivalence classes for each of the following functions? double abs(double num) {…} // returns absolute val of num int sign(double num) {…} // 1 if positive, -1 if negative, 0 if 0 string monthName(int month) {…} // month numbered 1-12 string dateString(int dayOfWeek, int day, int month) {…} 2 (maybe unexexpected numbers? E.g. Double.NaN, or Double.Infinity?) 3 13? (12 mos + invalid), 2? (1-12 and any other int?), maybe 4 classes? (30 days, 31 days, 28 or 29, invalid?) Combinations start to get kind crazy

Strategy: Boundary-based Selection Situation: We have all probably written code that looks like this— and not been 100% sure exactly how many times the loop will execute: for(i = 0; i <= 10; i++) { j++; } for(i = 0; i < 10; i++) { j++; } for(i = 1; i < 10; i++) { j++; } for(i = 1; i <= 10; i++) { j++; } Insight: Developers tend to make errors at “boundaries” of equivalence classes (e.g. using “<“ instead of “<=“) Idea: At each boundary, test value on either side of that boundary

Example /** Returns the “school type” (e.g. pre-school, primary school, elementary school, secondary school) depending on student’s age at the beginning of the school year */ string SchoolTypeForAge(double age); Five equivalence classes: pre-school kids (2-4y) primary-school age (5-8y) elementary-school age (9-14y) secondary-school age (15-17y) outside-of-range (<2, >18) We should definitely test 1, 2, 17, 18 We should probably test at each of these boundaries, too: Pre-school: 1,2, 4,5 Primary: 4,5, 8,9 …

#in-class What kinds of boundary conditions should we check for each of: string monthName(int mont) { … } // month is 1-12 int sign(double num) { … } // 1 if positive, -1 if negative, 0 if 0 bool CheckUsername(string name) { … } // false if null, empty, or over 12 chars long

Strategy: Path-based Selection Observation: Logical errors and incorrect assumptions are inversely proportional to a path’s execution probability. Idea: Design tests such that each of the execution paths will be covered by at least one test. Requires: Access to the source!

Starting the car 0. Start 1. Enter car 2 Starting the car 0. Start 1. Enter car 2. Do you have the key in your hand? 3. Check your pocket 4. Is it a physical key, or a FOB? 5. Press button on car 6. Insert key, and turn 7. Is the car started? 8. End Idea: construct a graph that illustrates each possible path of control 1 2 4 3 5 6 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 7 8

#in-class: How many paths through this code? Starting the car 0. Start 1. Enter car 2. Do you have the key in your hand? 3. Check your pocket 4. Is it a physical key, or a FOB? 5. Press button on car 6. Insert key, and turn 7. Is the car started? 8. End 1 2 4 3 5 6 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005 7 8 #in-class: How many paths through this code?

Exhaustively, there are 6 paths through the code 1 2 3 4 5 6 7 8 Exhaustively, there are 6 paths through the code But you would (probably) only need/want to test 4 paths: 0, 1, 2, 4, 6, 7, 8 0, 1, 2, 4, 5, 7, 8 0, 1, 2, 3, 7, 8 0, 1, 2, 3, 7, 2, …, 7, 8 Exercise: Figure out how this works with loops These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by R.S. Pressman & Associates, Inc., copyright © 1996, 2001, 2005

Strategy: State-Based Testing Observation: What we care about most of the time is whether our system is moving correctly from one state into the next Idea: Select tests that cover those transitions between states to ensure that we are correctly moving from one state to another http://www.desaware.com/img/articles/State1.jpg

Challenge: observing states? Recall: a state is comprised of all the values of the internal variables How do we observe what “state” we are in? Directly: through getters, or public states; we can insert “probes” or debug to determine what the private values are Indirectly: by observing the outputs

Example: File Transfer Protocol FTP: client-server protocol for transferring files Commands include: USER, PASS, STOR, RETR, QUIT, ... Server sends back responses There are ordering constraints on some commands: e.g. to login, USER must be immediately followed by PASS e.g. STOR can only succeed if logged in

Recall: STOR only works if authenticated

Identify the test cases we should explore for transition coverage to test an FTP server on its handling of authentication. Recall: STOR only works if authenticated

Observations Bugs “lurk in the corners” where the test suite isn’t exercising the program The strategies that we have explored focus on trying to increase the “code coverage” of the test (or ”test coverage”)

Learning Objectives You should now be able to identify, understand and use: Equivalence-based strategies for selecting test cases Boundary-based strategies for selecting test cases Path-based strategies for selecting test cases State-based strategies for selecting test cases