7. Equivalence Portioning
EQUIVALENCE
PORTIONING
1. Positive tests (clean tests):
– tests based on defined requirements
– tests based on common circumstances
2. Negative tests (dirty tests):
– tests based on errors/defects
– test based on special circumstances
8. Equivalence Portioning
EXAMPLE
A fitness tracker ‘Happy Tester’ measures the number of steps that are walked
each day and provides feedback to encourage the user:
Up to 1000 - Couch Potato!
Above 1000, up to 2000 - Lazy Bones!
Above 2000, up to 4000 - Getting There!
Above 4000, up to 6000 - Not Bad!
Above 6000 - Way to Go!
1000 2000 4000 6000
1001 2001 4001 6001
1. 0-1000
2. 1001-2000
3. 2001-4000
4. 4001-6000
5. 6001- +∞
9. Equivalence Portioning
BOUNDARY VALUES
Step 1: Identify equivalence classes
Step 2: Identify the boundary corresponding to each equivalent class
Step 3: Create test cases for each boundary value by selecting a
point on the boundary.
A B C
I II III IV
TWO-POINT BVA
B-1 B+1
10. Equivalence Portioning
EXAMPLE
50
A speed control and reporting system has the following characteristics:
If you drive 50 km/h or less, nothing will happen.
If you drive faster than 50 km/h, but 55 km/h or less, you will be warned.
If you drive faster than 55 km/h but not more than 60 km/h, you will be fined.
If you drive faster than 60 km/h, your driving license will be suspended.
The speed in km/h is available to the system as an integer value.
Which would be the most likely set of values (km/h) identified by applying the boundary value
analysis, where only the boundary values on the boundaries of the equivalence classes are
relevant?
a) 0, 49, 50, 54, 59, 60.
b) 50, 55, 60.
c) 49, 50, 54, 55, 60, 62.
d) 50, 51, 55, 56, 60, 61.
6055
51 56 61
17. Equivalence Portioning
DECISION TABLE
R1 R2 R3 R4 R5
CONDITIONS
User Inserts Valid Card F T T T T
User Enters Valid PIN - F T N T
3 Invalid PINs attempted - F - T -
Sufficient balance for the request - - F - T
ACTIONS
Reject Card Y N N N N
Prompt to Reenter PIN N Y N N N
Eat the Card N N N Y N
Dispense Requested Cash N N N N Y
20. Equivalence Portioning
STATE TRANSITION
What is the minimum number of cases we should make for sum validation?
▪ Determine all states.
▪ Consider and prioritize according to requirements all
ways which cover whole functionality.
▪ Identify all transitions.
▪ Create a test case for each way, that covers main
functionality.
▪ Create additional test cases that cover remaining
functionality (if it is needed).
How much times user has to enter money to get enough pay?
FIRST
22. Equivalence Portioning
BASE CHOICE TESTING
Param1 Param2 Param3
A 1 X
B 2 Y
C 3 Z
Test Case Param1 Param2 Param3
1 A 2 Y
2 B 2 Y
3 C 2 Y
4 A 1 Y
5 A 3 Y
6 A 2 X
7 A 2 Z
24. Equivalence Portioning
SYNTAX TESTING
Backus–Naur form or Backus normal form (BNF) is a notation technique
for context grammar for programming languages, document formats and
communication protocols.
25. Equivalence Portioning
SYNTAX TESTING
After BNF is approved, it is time to generate positive and negative cases:
Positive cases: find possible variants of values allowed by the individual elements
of the BNF definition, and then design cases to simply cover these variants.
Negative cases: define and apply possible mutations (e.g.: missing element,
unwanted extra element, invalid value for an element, and so on) to the
individual elements of the BNF definition.
27. Equivalence Portioning
SCENARIO TESTING
(USE CASE)
12 Ways to Create Good Scenarios (by Cem Kaner):
1. Write life histories for objects in the system.
2. List possible users, analyze their interests and objectives.
3. Consider disfavored users: how do they want to abuse your system?
4. List “system events.” How does the system handle them?
5. List “special events.” What accommodations does the system make for these?
6. List benefits and create end-to-end tasks to check them.
7. Interview users about famous challenges and failures of the old system.
8. Work alongside users to see how they work and what they do.
9. Read about what systems like this are supposed to do.
10. Study complaints about the predecessor to this system or its competitors.
11. Create a mock business. Treat it as real and process its data.
12. Try converting real-life data from a competing or predecessor application.
29. Equivalence Portioning
RANDOM TESTING
You’ll say it’s useless ‘monkey’ testing and I’ll say
- automate it.
• Random Users (objects)
• Testing validation with random data
• Randomized Behavior
• Fake the database
01. emailTextBx.click();
02. Random randomGenerator = new Random();
03. int randomInt = randomGenerator.nextInt(1000);
04. emailTextBx.sendKeys(“username” + randomInt + “@gmail.com”);
30. Equivalence Portioning
RANDOM TESTING
Sample Program Using
Random Class in Java
01. import java.util.Random;
02. public class RandomTestDataGenerator {
03. public static void main(String[ ] args) {
04. Random r = new Random ();
05. String fullName = “fullName” + r.nextInt();
06. String firstName = “firstName” + r.nextInt();
07. String lastName = “lastName” + r.nextInt();
08. String streetAddress = “address” + r.nextInt();
09. long phoneNumber = (long) (Math.random() * 100000 + 3333000000L);
10. String email = “email” + r.nextInt() + “@gmail.com”;
11. System.out.println (“The Full Name is : “ + fullName);
12. System.out.println (“The First Name is : “ + firstName);
13. System.out.println (“The Last Name is : “ + lastName);
14. System.out.println (“The Address is : “ + streetAddress);
15. System.out.println (“The Phone Number is : “ + phoneNumber);
16. System.out.println (“The Email is : “ + email);
17. }
18. }
31. Equivalence Portioning
RANDOM TESTING
Sample Program using
Faker API in Java
01. java.until.Locale;
02. import com.github.javafaker.Faker;
03. public class FakertestDataGenerator {
04. public static void main(String [ ] args) {
05. Locale locale = new Locale (“en-UKR”);
06. Faker faker = new Faker (locale);
07. String fullName = faker.name().fullName();
08. String firstName = faker.name().firstName();
09. String lastName = faker.name().lastName();
10. String phoneNumber = faker.phoneNumber().phoneNumber();
11. String address = faker.name().streetAddress();
12. String email = faker.internet().emailAddress();
13. System.out.println (“The Full Name is : “ + fullName);
14. System.out.println (“The First Name is : “ + firstName);
15. System.out.println (“The Last Name is : “ + lastName);
16. System.out.println (“The Address is : “ + streetAddress);
17. System.out.println (“The Phone Number is : “ + phoneNumber);
18. System.out.println (“The Email is : “ + email);
19. }
20. }
33. Equivalence Portioning
LCSAJ TESTING
(Linear Code Sequence and Jump)
Characteristics of LCSAJ:
o 100% LCSAJ means 100% Statement Coverage
o 100% LCSAJ means 100% Branch Coverage
o LCSAJ is 100% procedure or Function call Coverage
o 100% Multiple condition Coverage
34. Equivalence Portioning
STATEMENT TESTING
01. if (p = q) {
02. r = r + 1;
03. if (r < 5) {
04. s = 10;
05. }
06. } else if (p > q) {
07. s = 5;
08. }
How many test cases are needed to get
100% statement coverage?
Which combination of p, q and r
values will ensure 100 %
statement coverage?
35. Equivalence Portioning
STATEMENT TESTING
01. if (p = q) {
02. r = r + 1;
03. if (r < 5) {
04. s = 10;
05. }
06. } else if (p > q) {
07. s = 5;
08. }
if
r = r + 1
r < 5
p=q
p>q
s = 10 s = 5
ifif
statement
statement statement
Y
Y Y
N
NN
37. Equivalence Portioning
STATEMENT TESTING
01. if (p = q) {
02. r = r + 1;
03. if (r < 5) {
04. s = 10;
05. }
06. } else if (p > q) {
07. s = 5;
08. }
if
r = r + 1
r < 5
p=q
p>q
s = 10 s = 5
ifif
statement
statement statement
Y
Y Y
N
NN
1 2
2 TEST CASES FOR
STATEMENT COVERAGE
ARE REQUIRED
38. Equivalence Portioning
STATEMENT TESTING
if
“Enough, thanks”
b<35
a+b>40
if
Y N
if a+b > 40 THEN
Print “Enough, thanks”
ENDIF
If b < 35 THEN
Print “Please, add more”
ENDIF
“Please, add more”
Y N
ONLY 1 TEST CASE FOR
STATEMENT COVERAGE
IS REQUIRED
39. Equivalence Portioning
if
“Enough, thanks”
b<35
a+b>40
if
Y N
if a+b > 40 THEN
Print “Enough, thanks”
ENDIF
If b < 35 THEN
Print “Please, add more”
ENDIF
“Please, add more”
Y N
1
BRANCH TESTING
2
2 TEST CASES FOR
BRANCH COVERAGE
ARE REQUIRED
40. Equivalence Portioning
Y N
if a+b > 40 THEN
Print “Enough, thanks”
ENDIF
If b < 35 THEN
Print “Please, add more”
ENDIF
“Please, add more”
1 2
PATH COVERAGE
34
a+b>40
“Enough, thanks”
b<35
NY
4 TEST CASES FOR
PATH COVERAGE
ARE REQUIRED
41. Equivalence Portioning
01. if ((p == 0)II(q>0)) {
02. r = r + 1;
03. if (r < 5) {
04. s = 10;
05. }
06. } else if (p > q) {
07. s = 5;
08. }
if
r = r + 1
r < 5 p>q
s = 10 s = 5
ifif
Y
Y Y
N
NN
CONDITION COVERAGE
(p == 0)II(q>0)
42. Equivalence Portioning
LOOP COVERAGE
1. main()
2. {
3. int i, n, f;
4. printf (“n = “);
5. scanf (“%d’, &n);
6. if (n <0) {
7. printf (“Invalid: %dn”, n);
8. n = -1;
9. } else {
10. f =1;
11. for (i=1; i<=n; i++) {
12. f*= 1;
13. }
14. printf (“%d! =%dn”, n, f);
15. }
16. return n;
17. }
if
for
TC1 n=0
TC2 n=1
TC3 n=15
43. Equivalence Portioning
CYCLOMATIC COMPLEXITY
Cyclomatic complexity is a software metric used to indicate the
complexity of a program and is a metric for software quality.
M = E − N + 2P,
where
E = the number of edges of the graph.
N = the number of nodes of the graph.
P = the number of connected components.
46. Equivalence Portioning
ERRORS GUESSING
• Lessons gained from past releases
• Historical learning
• Past defects
• Production tickets
• Review Checklist
• Application UI
• Past test outcomes
• Risk reports of the application
• An assortment of information utilized for testing.
FAULT ATTACK
48. Equivalence Portioning
EXPLORATORY
TESTING
5 Main Activities:
• Identify the purpose of the product
• Identify functions
• Identify areas of potential instability
• Test each function and record problems
• Design and record a consistency verification test
51. Equivalence Portioning
DATA FLOW TESTING
Data Flow testing helps to find:
• A variable that is declared but never used within the program.
• A variable that is used but never declared.
• A variable that is defined multiple times before it is used.
• Deallocating a variable before it is used.
52. Equivalence Portioning
CONTROL FLOW
TESTING define x
use y
kill z
define x
use x
use z
kill z
use x
define z
define y
use z
use y
use z
kill y
define z
Control Flow - the sequence in which
operations are performed during the
execution of a test item.
Example:
~define correct, the normal case
define-use correct, the normal case
use-kill acceptable
use-define acceptable
~use major blunder
define-kill probable programming error
define-define suspicious, perhaps a programming error
54. Equivalence Portioning
REVIEWS
Informal Walkthrough Technical review Inspection
Documented no yes yes yes
Led by author yes yes no no
Use checklists no optional optional yes
Moderator
(facilitator)
no yes ideally trained trained
Scribe no mandatory mandatory mandatory
Individual
preparation
no optional mandatory mandatory
Reviewers colleague, buddy different people technical experts different experts
Potential defects
logs
may be may be mandatory mandatory
55. Equivalence Portioning
REVIEWS
Advantages:
• Pick things which really count
• Clearly plan and track activities
• Provide training to participants
• Continuously improve the process and tools
• Report results
• Each review has clear objective
• Right people involved
• Atmosphere of trust
• Defects found welcomed and expressed objectively
• Checklists/roles used
• Management support
• Testers welcome as reviewers
• Emphasis on learning and process improvement