1 Introduction
1 Introduction
Introduction to
Software Testing
Professor Phil McMinn
Who here likes software
testing?
Who here thinks testing is
hard?
Who thinks testing and
debugging are basically the
same thing?
Who thinks that testing is
to show that software
works?
Who thinks that testing is
to show that software
doesn’t work?
Who thinks that the idea
behind testing is to
reduce risks involved in
using software?
Who thinks that the
testing is to help in the
development of
higher quality software?
Beizer’s Maturity Model
Level 0:
Testing is the same as debugging
The basic, least mature view of testing is that of Level 0 – testing is the
same as debugging.
At Level 0 thinking, programmers get their programs to compile, then
debug the programs with a few arbitrary inputs.
This view does not distinguish between a program's incorrect behaviour
and a mistake within the program. It also does very little to help develop
software that is reliable or safe.
(… and testing is not the same as debugging, as demonstrated later.)
Level 1:
The purpose of software testing
is to show software works
A signi cant step up from the naive Level 0.
But, in any but the most trivial of programs, correctness is virtually
impossible to either achieve or demonstrate!
(… another point we will return to later in the lecture.)
fi
Level 2:
The purpose of software testing
is to show software doesn’t work
Although looking for failures is certainly a valid goal, it is also a
negative goal.
If a company is organised where testers and developers are on di erent
teams, you may have a situation where testers may enjoy nding
problems, but the developers never want to nd problems – they want the
software to work!
fi
fi
ff
“ Excellent testing
can make you
unpopular with
almost everyone! ”
— Bill McKeeman
Level 2 testing puts testers and developers into an adversarial
relationship, which can be bad for team morale.
Beyond that, when our primary goal is to look for failures, we are still
left wondering what to do if no failures are found:
Is our work done?
and if so…
Is our software very good or is our testing poor?
Level 3:
The purpose of software testing
is not to show anything in
particular, but just to reduce the
risk of using software
Level 3 thinking lets us accept the fact that whenever we use software,
we incur some risk.
Level 3 thinking lets us accept the fact that whenever we use software,
we incur some risk.
The risk may be small, and the consequences unimportant, or the risk
may be great and the consequences catastrophic, but risk is always
there.
This allows us to realise that the entire development team wants the same
thing – to reduce the risk of using the software.
In the same way, Level 4 testing means that the purpose of testing is
to improve the ability of the developers to produce higher quality
software.
fi
The best use of a spellchecker is not just to
nd misspelled words, but to improve our
ability to spell.
Every time the spell checker nds an
incorrectly spelled word, we have the
opportunity to learn how to spell the word
correctly.
With six ints that’s 232x6 or 2192 (≈ 6 x 1057) unique inputs to try!
Suppose each input takes ≈ 1 nanosecond to execute.
It would take 1041 years to try them all!
The Halting Problem and
Software Testing
The Halting Problem in Computer Science is basically the problem of not
knowing if a program will terminate given some input.
If we give an arbitrary program an input, it has been proven that no program can
be written that can say whether that original program will terminate.
And this is true in software testing: we don’t know if, given our test inputs,
whether the program being tested will get stuck in an in nite loop!
fi
“ Software testing
can only show the
presence, not the
absence of bugs
”
— Edsger Dijkstra
Uncomputable
Tractable problems Intractable problems
problems
Computable in theory
😎 😎 😭
Computable in practice
😎 🤔 😭
u g s i n a
Find the shortest route
i n g a ll b
Example Decryption F i nd ro g r a m
on a map t e r p
compu
ffi
The Oracle Problem
Even if we could
1) execute all software with all inputs
(i.e., if software testing was a tractable problem)
2) guarantee the software terminated with each input
(i.e., if software testing was a computable problem)
We would still need to solve the oracle problem – how to know, given
some input to a software system, that the output it gives is the
correct one.
The Oracle Problem a human being makes a
manual judgment
e.g. an assertion in JUnit
fi
How do Software Failures
Happen?
A Method and its Tests
A Method and its Tests
PASSED
FAILED
This method contains a bug. Or more precisely, a defect.
Where is the defect? How does it cause the method to fail?
Defects
Software failures always start with the execution of one or more
defects in the code.
A defect is simply a piece of faulty, incorrect code.
A defect may be a part of or a complete program statement, or may
correspond to statements that don’t exist that should exist.
Although programmers are responsible for making defects in the code,
they may not be technically always be at fault – the problem may have
arisen, for example, from a poorly speci ed set of requirements.
fi
The defect in our
example is with
the second loop
initialiser.
It should start
iterating at i + 1
to check for
duplicates of the
character at i, not
at i itself (which is
guaranteed to be
identical!)
Infections
An infection is what happens when the defect is executed, and the
program’s state is a ected.
When a program’s state is infected it starts to work incorrectly:
• Variables start to take on the wrong values
• Decisions made in the program are evaluated incorrectly, and the
execution path deviates from the correct one.
But at this point, it has not a ected the output of the program (and the
fault, so far, has had no observable e ect).
ff
ff
ff
The infection in
our example
causes the loop
starts iterating an
index in the string
too early.
(b) the test itself was incorrect, for example it made an incorrect
assertion about the behaviour of the software.
Testing vs Debugging
We can also now debunk the idea that testing and debugging are
the same.
Testing is the process of evaluating software by observing its
execution.
Debugging is the process of tracking failures/test failures back to the
defects that were ultimately responsible for them.
How do Software Failures Happen?
1. The program location
containing a defect is
reached during execution.
😫 Defect
2. The defect infects the
state of the program 🤢 Infection
3. The infection propagates to
the program’s output causing
a failure.
🤮 Failure
Defects are not
always reached
(executed)
Consider what happens
if the inputs string s is
empty.
PASSED
FAILED
How Software Failures
are Detected by Test Cases.
The RIPR model
Defect Reached 😫
State Infected 🤢
Infection Propagated 🤮
Failure Revealed 🤓
Roadmap of this Module
What we will cover – Weeks 1-5
Theoretical foundations (this lecture) Code Coverage
Structural
Types of testing
Logic
Automated and Manual
Data Flow
Unit, Integration, and System
Input Domain
Unit Testing
Good practices
Test doubles
What we won’t cover…
On the whole, we won’t be covering speci c technologies and
environments.
The practices and techniques we will cover apply to any software
system you are developing.
The course is designed to serve as the foundation of any testing
that you need to do.
Each domain has its own testing practices and tools, however, so you
will need to look for additional resources that focus on those when the
time comes.
fi
Assessment and Feedback
This module is solely assessed by an exam.
Preparation will be via the lab classes, where you will study problems
similar to those that will appear on the exam.
We will provide feedback individually and via model answers.
Computer Laboratory Classes
We will set problem sheets and practical computer-based exercises
that are designed to help you:
Phil McMinn José Rojas Islam Elgendy Megan Maton Ruizhen (Rui) Gu
Module Lecturer Module Lecturer Teaching Assistant Demonstrator Demonstrator
Weeks 1-5 Weeks 6-10 Practical Sessions Practical Sessions Practical Sessions
Additional Notes / Follow-Up
The Post O ce software scandal mentioned at the start of the
lecture was the subject of an episode of the BBC’s “Panorama”,
which may still be available here:
https://www.bbc.co.uk/iplayer/episode/m0016t20/panorama-the-post-office-scandal
ffi