SlideShare a Scribd company logo
Testing
Michael Heron
Introduction
• Getting a program running is only the first step.
• Getting it working is the next… and this is often more costly.
• Having a structured approach to systems testing is one of the
key requirements for building robust and correct software.
Testing
• Testing helps to ensure that a program is correct.
• But what do we mean by correct?
• There are a range of criteria that we can apply to any given
program to judge its correctness.
Testing
• Correctness:
• It must handle all the requested functionality for all
valid data.
• It must not generate unexpected behaviour.
• It must respond appropriately to all anticipated data.
• It must have sufficient error checking to ensure the
program will not produce unexpected results in the
case of being given unexpected input.
Testing
• This is a very tall order for most software
projects.
• Sometimes it’s even a tall order for very simple
projects.
• It is impossible to exhaustively test a program of
any significant complexity.
• There are just far too many variables.
• Not all of the variables are found in the program itself.
Testing
• The goal of testing is to reveal inadequacies in a
piece of software.
• This is an important point.
• Programmers are often not the best people to
write the test cases for their own programs.
• Many large companies have dedicated testing
departments to ensure a minimalisation of bias.
Testing
• As a developer, it is tempting to write biased test cases that
code is very likely to pass.
• A good test however is one that reveals a problem.
• A structured approach to testing involves creating a number
of strong test cases for a program and comparing the actual
results against the expected results.
Test Sets
• For each test case in a test set, documentation
should include:
• The exact input data and the conditions under which
the data were inputted.
• The purpose of the test.
• The exact output expected from the program with the
given test data.
• Once the test is completed, the actual output is
compared to the expected output.
Test Strategies
• The kind of test cases used in a given test set depends on the
kind of testing strategy adopted.
• There are two main families of testing:
• Black box testing
• White box testing
• We shall look at these in turn.
Black Box Testing
• Black box (or functional) testing is centred around creating a
set of test cases based on sample data that is representative
of all data.
• Black box testing requires no knowledge of the program
architecture… the program is a ‘black box’ that we cannot see
into.
• Think of Searle’s Chinese room.
Black Box Testing
• In Black Box testing, all we consider are the inputs and the
outputs.
• Because it is impossible to exhaustively test a program, we
must choose data that is representative of other data.
• We must also consider special cases where errors are
particularly likely.
Black Box Testing
• Consider a program designed to multiply two numbers
together.
• If it works for 1 * 1, and 2 * 2, you may think it is safe to think
it will work for any positive integer.
• But this is not always true.
• Consider the following table
Black Box Testing
Number 1 Number 2 Result
1 1 1
2 2 4
3 3 27
Black Box Testing
• It is important that you choose a large enough sample from
any representative set.
• It is also important to check for specific kinds of input:
• Boundaries
• Maximum and minimums
• Invalid input
Black Box Testing
• Boundaries are those areas where errors are very likely to
creep in because of the transition between sets.
• Between positive and negative
• Between valid and invalid
• These areas are often fruitful tests because programmers
often make errors in boundary checking:
Examples
• If (a = a) {
do_something();
}
vs
if (a == a) {
do_something();
}
Examples
• If (a > b) {
do_something();
}
vs
if (a >= b) {
do_something();
}
Examples
• For (int I = 0; I < 100; i++) {
do_something_with (i);
}
vs
for (int I = 0; I <= 100; i++) {
do_something_with(i);
}
Black Box Testing
• It is very easy for these kind of errors to slip into a program.
• The ramifications can often be very subtle.
• A good test case will take numerous samples from a
representative set and also check at the boundaries of each
set.
• Remember – good test cases are those that reveal errors.
White Box Testing
• A counterpoint to black box testing is White Box
(or structural) testing.
• In White Box testing we do not care about the
matching of expected output to actual output.
• We do care that every statement in a program
gets executed at some point.
• White Box testing requires significant knowledge
of a program’s architecture.
White Box Testing
• In White Box testing, test cases are developed to ensure every
path of execution through a program is touched.
• Where there are loops and conditionals, test cases should be
devised to ensure that these are executed at some point with
valid test data.
White Box Testing
• Consider the following piece of code:
public static void main (String args[]) {
int a, b;
a = Integer.parseInt (args[0]);
b = Integer.parseInt (args[1]);
if (a < b); {
System.out.println (“A is less than B”);
}
if (a > b) {
System.out.println (“A is greater than B”);
}
else {
System.out.println (“A is equal to B”);
}
}
White Box Testing
Value of
A
Value of
B
Expected Actual
1 2 A is less
than B
A is less
than B
A is equal
to B
2 1 A is greater
than B
A is less
than B
A is greater
than B
White Box Testing
• White box testing allows us to test every conditional to ensure
that it gets called with the right sets of data.
• White box testing is not a replacement for black box testing.
• The two approaches work best as complements to each other.
Complementary Approaches
• Why use White Box Testing in addition to Black Box Testing?
• Logic errors are usually made when coding for ‘special cases’.
The correct execution of these logic paths should be tested.
• Assumptions about execution paths can be incorrect, and white
box testing shows this.
• Errors are random, and just as likely to be on an obscure path as
a mainstream path.
Complementary Approaches
• Why use Black Box Testing in addition to White Box Testing?
• We can check to see how tightly a method conforms to the
software specification
• We can ensure reliability of user input.
• We cannot assume that just because an execution path is
followed that the logic will be correct. Black Box Testing
highlights this.
Unit Testing
• Most programs are more complex than the ones shown in this
lecture.
• How is it possible to test these using proper test cases?
• It is not possible to test most complex programs as a whole.
• It’s just too complicated.
Unit Testing
• Instead, we use a technique called unit testing.
• We take each of the methods or classes in turn and test them
with all valid sets of data in a harness.
• A harness is just a small program that calls the method with
various appropriate sets of data and outputs the returned values.
Unit Testing
• This takes advantage of the modularity of modern software
development.
• Once a unit has been tested with white and black box testing
and has deemed to be ‘correct’, then it is usually safe to
assume the unit will work correctly when called by the
program itself.
• However, this is not always true!
Integration Testing
• However, we can apply a more structured approach to this
also with Integration Testing.
• We start off with a unit that has no dependencies on other
units and test that to ensure that it works.
• Then we test any units that make use of that unit.
Integration Testing
• Once we have tested these, then we use Integration Testing to
test them together to ensure that the result is correct.
• This is a time consuming, but very valuable process.
• In this way, a whole program can be broken up into chunks
and then reintegrated with a good degree of confidence.
Summary
• Testing is vital in ensuring correctness in programming.
• It is however very time consuming and often frustrating.
• It is possible to develop a structured approach to testing that
makes debugging an easier process.

More Related Content

What's hot

Black box testing or behavioral testing
Black box testing or behavioral testingBlack box testing or behavioral testing
Black box testing or behavioral testing
Slideshare
 

What's hot (19)

Black box testing or behavioral testing
Black box testing or behavioral testingBlack box testing or behavioral testing
Black box testing or behavioral testing
 
An Insight into the Black Box and White Box Software Testing
An Insight into the Black Box and White Box Software Testing An Insight into the Black Box and White Box Software Testing
An Insight into the Black Box and White Box Software Testing
 
Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering
 
Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)Se (techniques for black box testing ppt)
Se (techniques for black box testing ppt)
 
H testing and debugging
H testing and debuggingH testing and debugging
H testing and debugging
 
Test case design techniques
Test case design techniquesTest case design techniques
Test case design techniques
 
Black box testing
Black box testingBlack box testing
Black box testing
 
c
cc
c
 
Blackbox
BlackboxBlackbox
Blackbox
 
Unit 2 - Test Case Design
Unit 2 - Test Case DesignUnit 2 - Test Case Design
Unit 2 - Test Case Design
 
Test Case Design and Technique
Test Case Design and TechniqueTest Case Design and Technique
Test Case Design and Technique
 
Test Case Design and Technique
Test Case Design and TechniqueTest Case Design and Technique
Test Case Design and Technique
 
Test Case Design and Technique
Test Case Design and TechniqueTest Case Design and Technique
Test Case Design and Technique
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
Black Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath MBlack Box Testing Techniques by Sampath M
Black Box Testing Techniques by Sampath M
 
Unit testing
Unit testingUnit testing
Unit testing
 
Whitepaper Test Case Design and Testing Techniques- Factors to Consider
Whitepaper Test Case Design and Testing Techniques- Factors to ConsiderWhitepaper Test Case Design and Testing Techniques- Factors to Consider
Whitepaper Test Case Design and Testing Techniques- Factors to Consider
 
Equivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysisEquivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysis
 
Dynamic Testing
Dynamic TestingDynamic Testing
Dynamic Testing
 

Viewers also liked

Representation of geometric figuers in Braille
Representation of  geometric figuers in BrailleRepresentation of  geometric figuers in Braille
Representation of geometric figuers in Braille
BIJIT GHOSH
 
Secure communication in Networking
Secure communication in NetworkingSecure communication in Networking
Secure communication in Networking
anita maharjan
 

Viewers also liked (20)

CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Representation of geometric figuers in Braille
Representation of  geometric figuers in BrailleRepresentation of  geometric figuers in Braille
Representation of geometric figuers in Braille
 
CPP04 - Selection
CPP04 - SelectionCPP04 - Selection
CPP04 - Selection
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a Program
 
CPP07 - Scope
CPP07 - ScopeCPP07 - Scope
CPP07 - Scope
 
CPP08 - Pointers
CPP08 - PointersCPP08 - Pointers
CPP08 - Pointers
 
CPP01 - Introduction to C++
CPP01 - Introduction to C++CPP01 - Introduction to C++
CPP01 - Introduction to C++
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
CPP10 - Debugging
CPP10 - DebuggingCPP10 - Debugging
CPP10 - Debugging
 
CPP12 - Algorithms
CPP12 - AlgorithmsCPP12 - Algorithms
CPP12 - Algorithms
 
CPP05 - Arrays
CPP05 - ArraysCPP05 - Arrays
CPP05 - Arrays
 
Secure communication in Networking
Secure communication in NetworkingSecure communication in Networking
Secure communication in Networking
 
CPP11 - Function Design
CPP11 - Function DesignCPP11 - Function Design
CPP11 - Function Design
 
CPP06 - Functions
CPP06 - FunctionsCPP06 - Functions
CPP06 - Functions
 
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and EncapsulationPHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
 
Refactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 TutorialRefactoring for Design Smells - ICSE 2014 Tutorial
Refactoring for Design Smells - ICSE 2014 Tutorial
 
Comparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for RegressionComparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for Regression
 
Handwritten Character Recognition
Handwritten Character RecognitionHandwritten Character Recognition
Handwritten Character Recognition
 
Does your configuration code smell?
Does your configuration code smell?Does your configuration code smell?
Does your configuration code smell?
 
CPP14 - Encapsulation
CPP14 - EncapsulationCPP14 - Encapsulation
CPP14 - Encapsulation
 

Similar to CPP09 - Testing

software testing types jxnvlbnLCBNFVjnl/fknblb
software testing types jxnvlbnLCBNFVjnl/fknblbsoftware testing types jxnvlbnLCBNFVjnl/fknblb
software testing types jxnvlbnLCBNFVjnl/fknblb
jeyasrig
 
Random testing
Random testingRandom testing
Random testing
Can KAYA
 
&lt;p>Software Testing&lt;/p>
&lt;p>Software Testing&lt;/p>&lt;p>Software Testing&lt;/p>
&lt;p>Software Testing&lt;/p>
Atul Mishra
 
An overview to Software Testing
An overview to Software TestingAn overview to Software Testing
An overview to Software Testing
Atul Mishra
 

Similar to CPP09 - Testing (20)

Testing
TestingTesting
Testing
 
Dynamic Testing
Dynamic TestingDynamic Testing
Dynamic Testing
 
Sorfware engineering presentation (software testing)
Sorfware engineering presentation (software testing)Sorfware engineering presentation (software testing)
Sorfware engineering presentation (software testing)
 
Unit 4 testing
Unit 4 testingUnit 4 testing
Unit 4 testing
 
Software Engineering TESTING AND MAINTENANCE
Software Engineering TESTING AND MAINTENANCESoftware Engineering TESTING AND MAINTENANCE
Software Engineering TESTING AND MAINTENANCE
 
CS8494 SOFTWARE ENGINEERING Unit-4
CS8494 SOFTWARE ENGINEERING Unit-4CS8494 SOFTWARE ENGINEERING Unit-4
CS8494 SOFTWARE ENGINEERING Unit-4
 
software testing types jxnvlbnLCBNFVjnl/fknblb
software testing types jxnvlbnLCBNFVjnl/fknblbsoftware testing types jxnvlbnLCBNFVjnl/fknblb
software testing types jxnvlbnLCBNFVjnl/fknblb
 
Software testing software engineering.pdf
Software testing software engineering.pdfSoftware testing software engineering.pdf
Software testing software engineering.pdf
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
Software Testing strategies, their types and Levels
Software Testing strategies, their types and LevelsSoftware Testing strategies, their types and Levels
Software Testing strategies, their types and Levels
 
Random testing
Random testingRandom testing
Random testing
 
Class9_SW_Testing_Strategies.pdf
Class9_SW_Testing_Strategies.pdfClass9_SW_Testing_Strategies.pdf
Class9_SW_Testing_Strategies.pdf
 
Testing fundamentals
Testing fundamentalsTesting fundamentals
Testing fundamentals
 
Test Case Design
Test Case DesignTest Case Design
Test Case Design
 
Test Case Design & Technique
Test Case Design & TechniqueTest Case Design & Technique
Test Case Design & Technique
 
&lt;p>Software Testing&lt;/p>
&lt;p>Software Testing&lt;/p>&lt;p>Software Testing&lt;/p>
&lt;p>Software Testing&lt;/p>
 
An overview to Software Testing
An overview to Software TestingAn overview to Software Testing
An overview to Software Testing
 
Testing Slides 2(Dynamic Testing Intro + Black Box Testing).pdf
Testing Slides 2(Dynamic Testing Intro + Black Box Testing).pdfTesting Slides 2(Dynamic Testing Intro + Black Box Testing).pdf
Testing Slides 2(Dynamic Testing Intro + Black Box Testing).pdf
 
Software Testing Introduction (Part 2)
Software Testing Introduction (Part 2)Software Testing Introduction (Part 2)
Software Testing Introduction (Part 2)
 
Unit Testing a Primer
Unit Testing a PrimerUnit Testing a Primer
Unit Testing a Primer
 

More from Michael Heron

More from Michael Heron (20)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 

CPP09 - Testing

  • 2. Introduction • Getting a program running is only the first step. • Getting it working is the next… and this is often more costly. • Having a structured approach to systems testing is one of the key requirements for building robust and correct software.
  • 3. Testing • Testing helps to ensure that a program is correct. • But what do we mean by correct? • There are a range of criteria that we can apply to any given program to judge its correctness.
  • 4. Testing • Correctness: • It must handle all the requested functionality for all valid data. • It must not generate unexpected behaviour. • It must respond appropriately to all anticipated data. • It must have sufficient error checking to ensure the program will not produce unexpected results in the case of being given unexpected input.
  • 5. Testing • This is a very tall order for most software projects. • Sometimes it’s even a tall order for very simple projects. • It is impossible to exhaustively test a program of any significant complexity. • There are just far too many variables. • Not all of the variables are found in the program itself.
  • 6. Testing • The goal of testing is to reveal inadequacies in a piece of software. • This is an important point. • Programmers are often not the best people to write the test cases for their own programs. • Many large companies have dedicated testing departments to ensure a minimalisation of bias.
  • 7. Testing • As a developer, it is tempting to write biased test cases that code is very likely to pass. • A good test however is one that reveals a problem. • A structured approach to testing involves creating a number of strong test cases for a program and comparing the actual results against the expected results.
  • 8. Test Sets • For each test case in a test set, documentation should include: • The exact input data and the conditions under which the data were inputted. • The purpose of the test. • The exact output expected from the program with the given test data. • Once the test is completed, the actual output is compared to the expected output.
  • 9. Test Strategies • The kind of test cases used in a given test set depends on the kind of testing strategy adopted. • There are two main families of testing: • Black box testing • White box testing • We shall look at these in turn.
  • 10. Black Box Testing • Black box (or functional) testing is centred around creating a set of test cases based on sample data that is representative of all data. • Black box testing requires no knowledge of the program architecture… the program is a ‘black box’ that we cannot see into. • Think of Searle’s Chinese room.
  • 11. Black Box Testing • In Black Box testing, all we consider are the inputs and the outputs. • Because it is impossible to exhaustively test a program, we must choose data that is representative of other data. • We must also consider special cases where errors are particularly likely.
  • 12. Black Box Testing • Consider a program designed to multiply two numbers together. • If it works for 1 * 1, and 2 * 2, you may think it is safe to think it will work for any positive integer. • But this is not always true. • Consider the following table
  • 13. Black Box Testing Number 1 Number 2 Result 1 1 1 2 2 4 3 3 27
  • 14. Black Box Testing • It is important that you choose a large enough sample from any representative set. • It is also important to check for specific kinds of input: • Boundaries • Maximum and minimums • Invalid input
  • 15. Black Box Testing • Boundaries are those areas where errors are very likely to creep in because of the transition between sets. • Between positive and negative • Between valid and invalid • These areas are often fruitful tests because programmers often make errors in boundary checking:
  • 16. Examples • If (a = a) { do_something(); } vs if (a == a) { do_something(); }
  • 17. Examples • If (a > b) { do_something(); } vs if (a >= b) { do_something(); }
  • 18. Examples • For (int I = 0; I < 100; i++) { do_something_with (i); } vs for (int I = 0; I <= 100; i++) { do_something_with(i); }
  • 19. Black Box Testing • It is very easy for these kind of errors to slip into a program. • The ramifications can often be very subtle. • A good test case will take numerous samples from a representative set and also check at the boundaries of each set. • Remember – good test cases are those that reveal errors.
  • 20. White Box Testing • A counterpoint to black box testing is White Box (or structural) testing. • In White Box testing we do not care about the matching of expected output to actual output. • We do care that every statement in a program gets executed at some point. • White Box testing requires significant knowledge of a program’s architecture.
  • 21. White Box Testing • In White Box testing, test cases are developed to ensure every path of execution through a program is touched. • Where there are loops and conditionals, test cases should be devised to ensure that these are executed at some point with valid test data.
  • 22. White Box Testing • Consider the following piece of code: public static void main (String args[]) { int a, b; a = Integer.parseInt (args[0]); b = Integer.parseInt (args[1]); if (a < b); { System.out.println (“A is less than B”); } if (a > b) { System.out.println (“A is greater than B”); } else { System.out.println (“A is equal to B”); } }
  • 23. White Box Testing Value of A Value of B Expected Actual 1 2 A is less than B A is less than B A is equal to B 2 1 A is greater than B A is less than B A is greater than B
  • 24. White Box Testing • White box testing allows us to test every conditional to ensure that it gets called with the right sets of data. • White box testing is not a replacement for black box testing. • The two approaches work best as complements to each other.
  • 25. Complementary Approaches • Why use White Box Testing in addition to Black Box Testing? • Logic errors are usually made when coding for ‘special cases’. The correct execution of these logic paths should be tested. • Assumptions about execution paths can be incorrect, and white box testing shows this. • Errors are random, and just as likely to be on an obscure path as a mainstream path.
  • 26. Complementary Approaches • Why use Black Box Testing in addition to White Box Testing? • We can check to see how tightly a method conforms to the software specification • We can ensure reliability of user input. • We cannot assume that just because an execution path is followed that the logic will be correct. Black Box Testing highlights this.
  • 27. Unit Testing • Most programs are more complex than the ones shown in this lecture. • How is it possible to test these using proper test cases? • It is not possible to test most complex programs as a whole. • It’s just too complicated.
  • 28. Unit Testing • Instead, we use a technique called unit testing. • We take each of the methods or classes in turn and test them with all valid sets of data in a harness. • A harness is just a small program that calls the method with various appropriate sets of data and outputs the returned values.
  • 29. Unit Testing • This takes advantage of the modularity of modern software development. • Once a unit has been tested with white and black box testing and has deemed to be ‘correct’, then it is usually safe to assume the unit will work correctly when called by the program itself. • However, this is not always true!
  • 30. Integration Testing • However, we can apply a more structured approach to this also with Integration Testing. • We start off with a unit that has no dependencies on other units and test that to ensure that it works. • Then we test any units that make use of that unit.
  • 31. Integration Testing • Once we have tested these, then we use Integration Testing to test them together to ensure that the result is correct. • This is a time consuming, but very valuable process. • In this way, a whole program can be broken up into chunks and then reintegrated with a good degree of confidence.
  • 32. Summary • Testing is vital in ensuring correctness in programming. • It is however very time consuming and often frustrating. • It is possible to develop a structured approach to testing that makes debugging an easier process.