Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.

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 Technique. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves.
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.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
OHT 9.1 Galin, SQA from theory to implementation © Pearson Education Limited 2004 Definitions and objectives Software testing strategies Software test.
Creator: ACSession No: 13 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringFebruary 2006 Testing - Techniques CSE300 Advanced Software Engineering.
Chapter 17 Software Testing Techniques
Software Engineering Testing Lecture 4 ASPI8-4 Anders P. Ravn, Feb 2004.
OHT 9.1 Galin, SQA from theory to implementation © Pearson Education Limited 2004 Definitions and objectives Software testing strategies Software test.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
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.
SOFTWARE TESTING WHITE BOX TESTING 1. GLASS BOX/WHITE BOX TESTING 2.
SOFTWARE QUALITY ASSURANCE Maltepe University Faculty of Engineering SE 410.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Software Systems Verification and Validation Laboratory Assignment 3
System/Software 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.
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.
Software Testing Strategies and Techniques. But First… Where have we been in this class gathering requirements defining the work to be done estimating.
Software Testing Testing types Testing strategy Testing principles.
Software Testing The process of operating a system or component under specified conditions, observing and recording the results, and making an evaluation.
Agenda Introduction Overview of White-box testing Basis path testing
Software Testing. 2 CMSC 345, Version 4/12 Topics The testing process  unit testing  integration and system testing  acceptance testing Test case planning.
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.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
White-box Testing.
CSC 480 Software Engineering Testing - I. Plan project Integrate & test system Analyze requirements Design Maintain Test units Implement Software Engineering.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
Software Testing and Quality Assurance 1. What is the objectives of Software Testing?
Theory and Practice of Software Testing
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
White Box Testing by : Andika Bayu H.
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 Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
CSC 395 – Software Engineering Lecture 27: White-Box Testing.
CHAPTER 9 - PART 1 Software Testing Strategies. Lesson Outlines Definitions and objectives Software testing strategies Software test classifications White.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
Software Testing. Software Quality Assurance Overarching term Time consuming (40% to 90% of dev effort) Includes –Verification: Building the product right,
Chapter 17 Software Testing Techniques
Software Testing.
Software Testing.
Chapter 13 & 14 Software Testing Strategies and Techniques
Structural testing, Path Testing
White-Box Testing Techniques
Types of Testing Visit to more Learning Resources.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software testing strategies 2
Software Testing (Lecture 11-a)
Chapter 14 Software Testing Techniques
Chapter 10 – Software Testing
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
Chapter 14 Software Testing Techniques
Control Structure Testing
CSE 1020:Software Development
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Unit Testing 101 Black Box v. White Box

Definition of V&V Verification - is the product correct Validation - is it the correct product

Background Info… Textbook's Definition of Testing: Software Testing is a formal process carried out by a specialized team in which a software unit, several integrated units or an entire software package are examined by running the programs on a computer. Testing is the single biggest SQA task. on average, 24% of the development budget is testing Code Testing ≠ Code Walkthrough Objectives of Testing: reveal errors after retesting, assurance of acceptable quality compile record of software errors textbook pages

Laws of Testing  The best person to test your code is someone else.  A good test is one that finds an error.  Testing can not prove the absence of errors.  Complete test coverage is impossible, so concentrate on problem areas.  It cost a lot less to remove bugs early.

Testing Stages Unit Testing modules of code Integration Testing design Validation Testing requirements System Testing system engineering today next class

Reality Check… Why not just run the whole thing and see if it gives us the right answer or if it crashes?

Unit Testing White Box Testing testing a module of code based on the source code Black Box Testing testing a module based on its description and/or the requirements specification Also called "functional" and "behavioral" testing Proof of Correctness mathematically-based analysis of the requirements, similar to theorem proving

White Box Testing Fundamentals White Box testing is much more expensive than Black Box testing. White Box is most appropriate when we must assure that the calculations are correct. Covering every possible path through a module is usually not practical. 10 if-then statements might require 1024 test cases instead, base the number of tests on the complexity of the module

Types of Code Coverage Function coverage Has each function in the program been executed? Statement coverage Has each line of the source code been executed? Condition coverage Has each evaluation point (such as a true/false decision) been executed? Path coverage Has every possible route through a given part of the code been executed? Entry/exit coverage Has every possible call and return of the function been executed?

Example One int example1 (int value, boolean cond1, boolean cond2) { if ( cond1 ) value ++; if ( cond2 ) value --; return value; } Total Statement Coverage with one case - True True. Total Path Coverage with four paths - TT TF FT FF. But, total path coverage is usually impractical, so Basis Path Testing is usually better.

Basis Path Testing Objective is to test each conditional statement as both true and false 1. Draw a Flow Graph 2. Determine the Cyclomatic Complexity CC = number of regions CC = E - N Max Number of tests = CC 4. Derive a basis set of independent paths 5. Generate data to drive each path

Flow Graphs simple sequence if then else whiledo until case statement

Example One - using basis path int example1 (int value, boolean cond1, boolean cond2) { 1 if ( cond1 ) 2 value ++; 3 if ( cond2 ) 4 value --; 5 return value; } Complexity = 3 Basis Paths Test Data 1 3 5false false true false true true

Example One - sample driver Test Data false true false true int example1 (int value, boolean cond1, boolean cond2) {... } print ("test one ", example1 (5, false, false)); print ("test two ", example1 (5, true, false)); print ("test three ", example1 (5, true, true));

Example Two float avg_negative_balance (int arraysize, float balances[]) { float total = 0.0; int count = 0; for I = 1 to arraysize if ( balances[I] < 0 ) total += balances[I]; count ++; end if; end for; return total / count; }

Example Two - using basis path float avg_negative_balance (int arraysize, float balances[]) { 1 float total = 0.0; int count = 0; 2 for I = 1 to arraysize 3 if ( balances[I] < 0 ) 4 total += balances[I]; count ++; end if; end for; 5 return total / count; } Basis Paths Test Data arraysize = arraysize = 1, balance[1] = arraysize = 1, balance[1] = T F

Example Two - Test Report Test #Test DataResult 1array size = 0failed 2size = 1passed array = [ 25 ] 3size = 1passed array = [ -25 ] Errors not detected: precious errors when "total" gets very small

Loop Testing Errors often occur near the beginnings and ends of loops. For each loop that iterates max N times, test N = 0 N = 1 N = max -1 N = max N = max + 1 For nested loops repeat above for the innermost loop, outer loop iterates once then repeat all 5 possibilities for outer loop, while inner loop iterates only once

Example Two - using loop testing float avg_negative_balance (int arraysize, float balances[]) { float total = 0.0; int count = 0; for I = 1 to arraysize if ( balances[I] < 0 ) total += balances[I]; count ++; end if; end for; return total / count; } Test Case Test Data N = 0 size = 0 N = 1 size = 1 N = max-1 size = 999 (if SRS says max=1000) N = max size = 1000 N = max+1 size = 1001, but array has only 1000 elements

Simple Black Box Testing Create Test Cases for Easy-to-compute data Typical data Boundary / extreme data Bogus data

Boundary Value Analysis Form of Black Box testing similar to "Equivalence Partitioning" Rationale: off-by-one is the most common coding error errors usually occur near the ends - boundaries

BVA Test Cases if an input specifies a range bounded by A and B, 1. test value = A 2. test value = B 3. test value < A 4. test value > B do the same for outputs

Example Two - using BVA Inputs and Outputs to be Tested: Inputs size range from 0 to 1000 array of balances elements are positive and negative floats Outputs average of negative balances

Example Two - using BVA Test Cases: Based on Input Boundaries 1. size = 0 2. size = 1, balance[1] is negative 3. size = 1, balance[1] is positive 4. size = 1000, all negatives 5. size = 1000, all positives 6. size = 1001 Based on Output Boundaries 7. a test where the average negative is huge 8. a test where the average negative is small

Random Testing Method: just randomly generate test data Advantage: very easy to generate lots of test cases Disadvantage: you have to get lucky that a test case will find an error

A the moral of this story is… Use a testing tool.

One last example... void count_balances (int arraysize, float balances[], out int people_we_owe, out int people_who_owe_us) { people_we_owe = 0; people_who_owe_us = 0; for I = 1 to arraysize if ( balances[I] < 0 ) people_who_owe_us ++; else people_we_owe ++; }

Next Time… Integration Testing System Testing User Interface Testing Writing a Test Plan