6 SoftEng Testing
6 SoftEng Testing
Software Testing
www.cs.uoi.gr/~zarras/http://www.cs.uoi.gr/~zarras/se.htm
Testing fundamentals
1
16/5/2024
Errors
Faults
Bugs !!!
Failures
2
16/5/2024
Errors
Error
3
16/5/2024
Faults
Fault
4
16/5/2024
Failures
Failure
10
5
16/5/2024
11
Software testing
12
6
16/5/2024
13
Test cases
The essence of software testing is to determine
a set of test cases for the item to be tested.
14
7
16/5/2024
15
16
8
16/5/2024
17
18
9
16/5/2024
19
Testing targets
20
10
16/5/2024
http://xunitpatterns.com/index.html
Examples:
https://github.com/zarras/myy803-junit-mockito-
tutorials/tree/master/basic-xunit-patterns
21
22
11
16/5/2024
23
24
12
16/5/2024
Test Method
We encode each test as a single Test Method on some class.
Variations:
Constructor test
25
26
13
16/5/2024
27
28
14
16/5/2024
29
Assertion Method
We call a xUnit assertion method to evaluate whether an expected
outcome has been achieved.
Variations:
Expected exception
assertions.
30
15
16/5/2024
31
Assertion Message
We include a descriptive string argument in each call to an Assertion
Method.
32
16
16/5/2024
33
Test Runner
We execute the xUnit framework’s specific program that instantiates
and executes the Testcase Objects.When we have many tests to run
we can organize them in Test Suites.
34
17
16/5/2024
http://xunitpatterns.com/index.html
Examples:
https://github.com/zarras/myy803-junit-mockito-
tutorials/tree/master/fixture-patterns/
35
36
18
16/5/2024
Fresh Fixture
Each test constructs its own brand-new test fixture for its own
private use.
37
Shared Fixture
We reuse the same instance of the test fixture across many
tests.
If we want to avoid slow tests.
38
19
16/5/2024
39
40
20
16/5/2024
41
42
21
16/5/2024
43
44
22
16/5/2024
http://xunitpatterns.com/index.html
Examples:
https://github.com/zarras/myy803-junit-mockito-
tutorials/tree/master/result-verification-patterns
45
46
23
16/5/2024
47
48
24
16/5/2024
State Verification
We inspect the state of the system under test after it has been
exercised and compare it to the expected state.
Variations:
49
50
25
16/5/2024
Behavior Verification
We capture the indirect outputs/interactions of the SUT with DOC as
they occur and compare them to the expected behavior.
51
Test Spy
We use a Test Spy to wrap the DOC to capture the indirect output
calls made to DOC by the SUT for later verification by the test.
Spy Implementation
options:
Examples
https://github.com/zarras/myy803-junit-mockito-tutorials/tree/master/test-
double-patterns/
52
26
16/5/2024
53
Test Double
We replace the DOC that the SUT depends on with a much lighter-
weight implementation.
Fake Object – a test double
that we just call.
Examples Implementation:
https://github.com/zarras/myy803-junit- Use a mocking framework like
mockito-tutorials/tree/master/test-double- mockito (mock() and when-then-
patterns/ return/throw commands).
54
27
16/5/2024
Testing techniques
55
56
28
16/5/2024
57
58
29
16/5/2024
Ad-hoc testing
59
60
30
16/5/2024
61
62
31
16/5/2024
63
class Triangle {
public void checkType(int sideA, int sideB, int sideC){
if((sideA < 1) || (sideA > 200) || (sideB < 1) ||
(sideB > 200) ||(sideC < 1) || (sideC > 200)) {
System.out.println("Wrong input");
return;
}
if(
// then check if the triangle inequality holds
(sideA >= sideB + sideC) ||
(sideB >= sideA + sideC) ||
(sideC >= sideA + sideB)){
System.out.println("Not a Triangle");
return;
}
// check if it is equilateral
if((sideA == sideB) && (sideA == sideC) && (sideB == sideC)){
System.out.println("The triangle is equilateral");
return;
}
// if not equilateral, check if it is isosceles
if((sideA == sideB) || (sideA == sideC) || (sideB == sideC)){
System.out.println("The triangle is isosceles");
return;
}
// otherwise it is scalene
System.out.println("The triangle is scalene");
return;
}
}
64
32
16/5/2024
65
66
33
16/5/2024
67
class Triangle {
public void checkType(int sideA, int sideB, int sideC){
if((sideA < 1) || (sideA > 200) || (sideB < 1) ||
(sideB > 200) ||(sideC < 1) || (sideC > 200)) {
System.out.println("Wrong input");
return;
}
if(
// then check if the triangle inequality holds
(sideA >= sideB + sideC) ||
(sideB >= sideA + sideC) ||
(sideC >= sideA + sideB)){
System.out.println("Not a Triangle");
return;
}
// check if it is equilateral
if((sideA == sideB) && (sideA == sideC) && (sideB == sideC)){
System.out.println("The triangle is equilateral");
return;
}
// if not equilateral, check if it is isosceles
if((sideA == sideB) || (sideA == sideC) || (sideB == sideC)){
System.out.println("The triangle is isosceles");
return;
}
// otherwise it is scalene
System.out.println("The triangle is scalene");
return;
}
}
68
34
16/5/2024
69
Boundary value analysis does not make much sense for boolean
variables; we can use as the extreme values TRUE and FALSE.
70
35
16/5/2024
Math preliminaries
A1 ∪ A2 ∪ … ∪ An = B, and i ≠ j ⇒ Ai ∩ Aj = ∅.
71
72
36
16/5/2024
Our target set B is the possibly infinite set of input tuples, i.e. B = dom(v1) x
dom(v2) x … dom(vn)
Then the idea is to select at least one test case from each partition element
Ai.
73
class Triangle {
public void checkType(int sideA, int sideB, int sideC){
……….
}
}
74
37
16/5/2024
75
76
38
16/5/2024
77
Given a program/function,
its program graph is a
directed graph in which
nodes are statement
fragments, and edges
represent flow of control.
78
39
16/5/2024
79
80
40
16/5/2024
81
Statement testing
82
41
16/5/2024
Branch testing
83
Path testing
In path testing our goal is to select a set of test
cases T that satisfies the path coverage criterion.
84
42
16/5/2024
If (x) {
}
…
If (y) {
}
…
85
86
43