Slides

WARNING
These slides are not optimized for printing or
exam preparation. These are for lecture
delivery only.
These slides are made for PowerPoint 2010.
They may not show up well on other
PowerPoint versions. You can download
PowerPoint 2010 viewer from here.
These slides contain a lot of animations. For
optimal results, watch in slideshow mode.
While you wait for the lecture to start, design test cases for these two methods.
/* Returns true if the name is non-empty and
not null and not longer than 40 chars. */
Test input
Expected
null
false
Test input
Expected
null,0
exception
public boolean isValidName(String name) {
// ...
}
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
Storage.save(name, score);
}
77577 OR
How many test cases
do you have for the
saveScore method?.
count {answer}
e.g. count 9
tinyurl.com/answerpost
/* Returns true if the name is non-empty and
not null and not longer than 40 chars. */
Test input
Expected
null
false
Test input
Expected
null,0
exception
public boolean isValidName(String name) {
// ...
}
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
Storage.save(name, score);
}
/* Returns true if the name is non-empty and
not null and not longer than 40 chars. */
Test input
Expected
null
false
False
public boolean isValidName(String name) {
// ...
}
“ ”
False
Length==41
False
Length==50
False
Length==40
True
Length==10
True
Equivalence partition =
A group of inputs that are
likely to be treated
similarly by the SUT.
Equivalence
partitions
Values
null
null
empty
“
too long
length = 41 , 50
right size
40, 10
”
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
Storage.save(name, score);
}
Equivalence
partitions
Values
null
null
empty
“
too long
length = 41 , 50
right size
40, 10
”
Test input
Expected
null
False
“ ”
False
Length==41
False
Length==50
False
Length==40
True
Length==10
True
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
Test input
Expected
“new guy”, 0 success
null , -3 exception
“existing guy”, 5 exception
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
Storage.save(name, score);
}
name
score
Eq. partitions
Values
invalid
Any invalid e.g. null
exists
Any existing name e.g. “existing guy”
new
Any valid new name e.g. “new guy”
any
any
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
Test input
“new guy”, 0 success
null , -3 exception
“existing guy”, 5 exception
if (Storage.isFound(name)) {
throw new StorageException("already exists"); Test input
}
Storage.save(name, score);
}
Is this a unit test or an integration test?
Integration tests are choreography
tests. They do not test components.
They test how well the assembly of
components dance together.
If Unit testing , we should use stubs
for dependencies isValidName etc.
Expected
Expected
null
False
“ ”
False
Length==41
False
Length==50
False
Length==40
True
Length==10
True
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
Test input
Expected
“new guy”, 0 success
null , -3 exception
“existing guy”, 5 exception
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
storage.save(name, score);
}
Do we really
need to test
this method?
/* Throws StorageException if name is not valid
or if name already exists in the database. */
public void saveScore(String name, int score)
throws StorageException {
if (!isValidName(name)) {
throw new StorageException("invalid name");
}
Test input
Expected
“new guy”, 0 success
null , -3 exception
“existing guy”, 5 exception
if (Storage.isFound(name)) {
throw new StorageException("already exists");
}
Storage.save(name, score);
}
Do we really
need these
tests?
Where we are…
1:
desc: send budget
deadline: Thu 22nd September
2:
desc: review buddy program
deadline: Wed 21st September
..s bud
1. Aim to create a gem
you will be proud to
wear
2. Polish, check, polish,
check, polish, check,…
3. Sharpen your tools
once in a while
Today’s theme
?
Nearing completion.
Gearing up for bigger projects.
Estimate the statement coverage of this method for
these three test cases.
Test input
Expected
“new guy”, 0 success
null , -3 exception
“”, 5 exception
1
2
a) about 50%
b) about 80%
c) 100%
3
4
5
cover {a|b|c}
77577 OR
e.g. cover c
tinyurl.com/answerpost