Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Assignment Cover Sheet

 The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers are
aware of this and will disregard it.

Student Details

Student Number 1 0 4 4 9 3 1 4

Family Name PERERA Given Name BERNEDETTE

Unit Details

Unit Code CSI3105 Unit Title SOFTWARE TESTING

Name of Lecturer PROFESSOR C.PENG LAM Due Date 04 / APRIL / 2018


MATHEMATICAL CONCEPTS, Group or Tutorial
Topic of Assignment INDIVIDUAL
BLACK-BOX TESTING & JUNIT (if applicable)
ACBT
Course COMPUTER SCIENCE Campus COLOMBO
I certify that the attached assignment is my own work and that any material drawn from other sources has been
acknowledged. This work has not previously been submitted for assessment in any other unit or course.
Copyright in assignments remains my property. I grant permission to the University to make copies of assignments
for assessment, review and/or record keeping purposes. I note that the University reserves the right to check my
assignment for plagiarism. Should the reproduction of all or part of an assignment be required by the University for
any purpose other than those mentioned above, appropriate authorisation will be sought from me on the relevant
form.

Manual Submission
If handing in an assignment in a paper or other physical form, sign here to indicate that you have read this form, filled it in
completely and that you certify as above.

Signature Date Office Use Only

Electronic Submission

OR, if submitting this paper electronically as per instructions for the unit, place an ‘X’ in the box below to
indicate that you have read this form and filled it in completely and that you certify as above. Please
include this page with your submission. Any responses to this submission will be sent to your ECU
email address.
21/May/2018
Agreement  select check box Date

For procedures and penalties on late assignments please refer to the University Admission, Enrolment and Academic Progress
Rules - rule 24, and the ECU Course and Unit Delivery and Assessment Policy

The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers
are aware of this and will disregard it.
The ECU English Language Proficiency Measure (Feb 2014)
Levels of proficiency Low proficiency Developing Moderate proficiency High proficiency
proficiency
Incorrect or inappropriate Aspects of writing are Aspects of writing are
aspects of writing Incorrect or inappropriate mostly accurate. appropriate and
Aspects of writing obscure meaning in aspects of writing Mistakes rarely affect optimally constructed,
(Indicate with an X main area(s) many places. obscure meaning in clarity of meaning. allowing clarity of
needing improvement) some places. Minor editing needed to meaning.
Significant editing needed clarify the meaning, Meaning is clear and
to clarify the meaning, Some editing needed to along with careful needs only a light
along with extensive clarify the meaning, proofreading to correct proofread to correct
proofreading to correct along with extensive technical errors. technical errors.
technical errors. proofreading to correct
technical errors.
Sentence structure

 1. sentence completeness

 2. sentence length

 3. phrase/clause order

 4. use of conjunctions

 5. word order

 6. punctuation

Word use

 7. word choice

 8. word form

 9. word omission/redundancy

 10. verb tense/agreement

 11. spelling

 12. apostrophes

Sentence Structure Word Use

1. Sentence completeness: sentence includes subject, verb a 7. Word choice: words are correct and appropriate for
complete thought. the context.
2. Sentence length: length is appropriate to context or 8. Word form: correct part of speech is used, e.g., [to]
disciple affect / [the] effect.
9. Word omission/redundancy: words should not be
3. Phrase/clause order: parts of the sentence (phrases and
missing or be unnecessarily repetitive.
clauses) are ordered logically.
10. Verb tense/agreement: correct use of verbs that
4. Use of conjunctions: linking words are used correctly to
indicate time and correct word forms that agree
show the relationship between ideas.
grammatically with other words in the sentence.
5. Word order: words are ordered correctly in a sentence.
11. Spelling: correct spelling is used.
6. Punctuation: the correct use of full stops, commas,
12. Apostrophes: indicate ownership or contraction.
semicolons, colons and capitals.
MATHEMATICAL CONCEPTS,
BLACK-BOX TESTING & JUNIT
Assessment 01

Minor Assessment 01

Student Name: Bernedette Perera


Student Number: 10449314
Unit: CSI3105
CSI3105 SOFTWARE TESTING – Minor 01

Table of Contents
Task A: Mathematical Preliminaries ..........................................................................................1
1. Truth Values ...................................................................................................................1
2. Boolean Expression (leap year)......................................................................................1
3. Boolean Expression (variable x) .....................................................................................1
4. Regular Expression .........................................................................................................1
Task B: Control Flow Graph........................................................................................................1
1. List all Paths ...................................................................................................................1
2. Control Flow Graph ........................................................................................................1
2.1. Description of basis path .........................................................................................2
2.2. List of the set of basis path ......................................................................................2
Task C: Black-box Testing and Junit ...........................................................................................3
1. Payroll Program using Eclipse ........................................................................................3
2. Testing ............................................................................................................................7
2.1. Equivalence Partitioning (EP): .................................................................................7
2.1.1. Input Domain....................................................................................................7
2.1.2. Equivalence Classing ........................................................................................8
2.1.3. Combine Equivalence Classes ..........................................................................9
2.1.4. Infeasible Equivalence Classes .........................................................................9
2.1.5. Weak / Strong Equivalence Class Testing.........................................................9
2.2. Boundary Value Analysis (BVA) .............................................................................11
2.2.1. Hours Worked ................................................................................................11
2.2.2. Hourly Rate for Employee Type C ..................................................................11
2.2.3. Hourly Rate for Employee Type P ..................................................................12
2.2.4. Hourly Rate for Employee Type F...................................................................12
2.3. Test Cases ..............................................................................................................13
2.3.1. Function to be tested: validateEmpID ...........................................................13
2.3.2. Function to be tested: validateEmpType .......................................................14
2.3.3. Function to be tested: validateHourlyRate for Employee Type C..................15
2.3.4. Function to be tested: validateHourlyRate for Employee Type P ..................16
2.3.5. Function to be tested: validateHourlyRate for Employee Type F ..................17
2.3.6. Function to be tested: validateHrsWorked ....................................................18
2.4. JUnit .......................................................................................................................19
2.4.1. Employee ID Test ............................................................................................19
2.4.2. Employee Type Test .......................................................................................20
2.4.3. Hourly Rate Test .............................................................................................20
2.4.4. Hours Worked Test.........................................................................................22
Appendix ..................................................................................................................................23
1. Screenshots ..................................................................................................................23
1.1. JUnit .......................................................................................................................23
1.2. Employee ID ...........................................................................................................25

10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01

1.3. Employee Type ......................................................................................................25


1.4. Hourly Rate for Employee Type C ..........................................................................25
1.5. Hourly Rate for Employee Type P ..........................................................................26
1.6. Hourly Rate for Employee Type F ..........................................................................26
1.7. Hours Worked ........................................................................................................27
1.8. Outputs the Results of Payroll Program ................................................................27

Tables of Figures
Figure 1: Control Flow Graph .....................................................................................................1
Figure 2: BVA of hours worked ................................................................................................11
Figure 3: BVP of hourly rate - type C........................................................................................11
Figure 4: BVP of hourly rate - type P........................................................................................12
Figure 5: BVP of hourly rate - type F ........................................................................................12
Figure 6: JUnit Tests Screenshot ..............................................................................................23
Figure 7: JUnit execution on All Tests ......................................................................................24

Table of Tables
Table 1: List of set of basis path .................................................................................................2
Table 2: Input Domain ...............................................................................................................7
Table 3: Equivalence Classing ....................................................................................................8
Table 4: Infeasible Equivalence Classes .....................................................................................9
Table 5: Weak Equivalence Class ...............................................................................................9
Table 6: Strong Equivalence Class ............................................................................................10
Table 7: Test case for Employee ID ..........................................................................................13
Table 8: Test case for Employee Type .....................................................................................14
Table 9: Test case for hourly rate - type C ...............................................................................15
Table 10: Test case for hourly rate - type P .............................................................................16
Table 11: Test case for hourly rate - type F .............................................................................17
Table 12: Test case for hours worked ......................................................................................18

10449314 Page |2
CSI3105 SOFTWARE TESTING – Minor 01

Task A: Mathematical Preliminaries


1. Truth Values

a) P(81) - True
b) P(27) - False
c) P(121) - False
d) P(225) - True

2. Boolean Expression (leap year)

E = ((year % 4 == 0)  (year % 100 != 0  year % 400 == 0))

3. Boolean Expression (variable x)

E = ( y > 50 ) ∨ ( x < 40 ∧ x > 75)

4. Regular Expression

a) True
b) True
c) True
d) False

10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01

Task B: Control Flow Graph


1. List all Paths

E = {( Start,1 ), ( 1,2 ), ( 1,3 ), ( 2,3 ), ( 3,4 ), ( 3,5 ), ( 4,7 ), ( 5,6 ), ( 5,7 )}

P1 = [ 1 – 2 – 3 – 5 – 7 ]
P2 = [ 1 – 2 – 3 – 5 – 6 – 7 ]
P3 = [ 1 – 3 – 4 – 7 ]
P4 = [ 1 – 3 – 5 – 7 ]
P5 = [ 1 – 3 – 5 – 6 – 7 ]
Total: 5 Paths

2. Control Flow Graph

Assumptions:
Assuming that will have to get the file first in order to run the while loop, I have
added a statement at the beginning of the code to get the file. X: Get the File

Figure 1: Control Flow Graph

10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01

2.1. Description of basis path


A path is a collection of Nodes linked with Directed Edges. Nodes are statements or sequence of
statements and a simple basic block represents as one node. A basic block is a block which executes in a
sequence manner without changing the path, where it has a unique entry and exit points.
CGF is a graphical representation of the control flow inside of a program unit.

Basis path includes one or more linearly independent complete paths through a given CGF of a particular
program and each path is known as basis path. It is used for testing which is based on a white box method
in order to create test cases and it involves execution of all possible blocks in a program and obtains
maximum path coverage with least number of test cases. The test cases are based on the flows or logical
path taken from the program.
A basis path is also known as basis set, where the objective is to evaluate the CFG to define a set of linearly
independent paths of execution and it covers all the nodes and edges. Number of basis path is equal to
the cyclomatic complexity, according to the above CFG diagram in Figure 1 the cyclomatic complexity is
equal to:
V(G) = Edges – Nodes + 2
= 11 – 9 + 2 = 4

The following lists all the paths of CFG drawn in Figure 1 above:
E = { (Start, A), (A, B), (A, J), (B, D), (B, C), (C, A), (C, H), (D, F), (D, E), (F, G), (E, G), (G, H), (H, J), (J, End) }

P1 = [ A – J ]
P2 = [ A – B – D – F – G – H – J ]
P3 = [ A – B – D – E – G – H – J ]
P4 = [ A – B – C – H – J ]
Total Paths: 4 paths

2.2. List of the set of basis path

Block Lines Entry Point Exit Point


A 1 1 1 1
B 2 2,3 2 3
C 3 4,5 4 5
D 4 7 7 7
E 5 8,9 8 9
F 6 11 11 11
G 7 12 12 12
H 8 14 14 14
J 9 16 16 16
Table 1: List of set of basis path

10449314 Page |2
CSI3105 SOFTWARE TESTING – Minor 01

Task C: Black-box Testing and Junit

1. Payroll Program using Eclipse

/**
* Student Name: Bernedette Perera
* Student ID : 10449314
* Unit : Software Testing | CSI3105
*/
import javax.swing.*;
import java.text.DecimalFormat;

public class PayrollProgram {

public static void main(String[] args) {

/**
* Employee ID and Employee Type
*/
String empID = "",
empType = "";

/**
* Hours Worked for the week
*/
int hrsWorked = 0;

/**
* Hourly Rate and Total Wages
*/
double hourlyRate = 0,
totalWages = 0;

/**
* Validation Check on
* Employee ID, Employee Type, Hours Worked, Hourly Rate
*/
boolean isValidEmpID = false,
isValidEmpType = false,
isValidHrsWorked = false,
isValidHourlyRate = false;

/**
* Input for Employee ID
*/
do {
String temp = JOptionPane.showInputDialog("Enter your Employee ID:");
empID = validateEmpID(temp);

if (empID != "0") {
isValidEmpID = true;
}

}while (!isValidEmpID);

10449314 Page |3
CSI3105 SOFTWARE TESTING – Minor 01

/**
* Input for Employee Type
*/
do {
String temp = JOptionPane.showInputDialog("Enter your Employee Type:");
empType = validateEmpType(temp.toUpperCase());

if (empType != "0") {
isValidEmpType = true;
}

}while (!isValidEmpType);

/**
* Input for Hourly Rate
*/
do {
String temp = JOptionPane.showInputDialog("Enter your hourly rate:");
hourlyRate = validateHourlyRate(empType, temp);

if (hourlyRate != 0) {
isValidHourlyRate = true;
}

}while (!isValidHourlyRate);

/**
* Input for Hours Worked
*/
do {
String temp = JOptionPane.showInputDialog("Enter your worked
hours for this week:");
hrsWorked = validateHrsWorked(temp);

if (hrsWorked != 0) {
isValidHrsWorked = true;
}

}while (!isValidHrsWorked);

/**
* Get Total Wages for the week
*/
totalWages = calculateWages(hourlyRate, hrsWorked);

/**
* Output of the Payroll Program
*/
JOptionPane.showMessageDialog
(null,
"Employee ID: " + empID + "\n" +
"Employee Type: " + empType + "\n" +
"Hours Worked: " + hrsWorked + " hours" + "\n" +
"Weekly Gross Pay: " + "$" + totalWages
);
}

10449314 Page |4
CSI3105 SOFTWARE TESTING – Minor 01

/**
* Validate Employee ID
* @param id
* @return String
*/
public static String validateEmpID(String id) {

int empID;

if (id.length() == 5) {
try {
empID = Integer.valueOf(id);
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Error: Employee ID must
contain only numbers!");
return "0";
}

id = Integer.toString(empID);

while (id.length() < 5) {


id = "0" + id; //Pad 0s in left
}
return id;
}
else {
JOptionPane.showMessageDialog(null, "Error: Enter a 5-digit number!");
return "0";
}
}

/**
* Validate Employee Type
* @param type
* @return String
*/
public static String validateEmpType(String type) {

if (type.equals("C") || type.equals("P") || type.equals("F")) {


return type;
}
else {
JOptionPane.showMessageDialog(null, "Error: Enter a valid
Employee Type!");
return "0";
}
}

10449314 Page |5
CSI3105 SOFTWARE TESTING – Minor 01

/**
* Validate Hourly Rate for Employee Type C, P, F
* @param hrs
* @param type
* @return double
*/
public static double validateHourlyRate(String type, String rate) {
double hourlyRate;

try {
hourlyRate = Double.parseDouble(rate);
}catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: Hourly Rate must
be numeric!");
return 0;
}
if (type.equals("C") && !(hourlyRate >= 20 && hourlyRate <= 35)) {
JOptionPane.showMessageDialog(null, "Employee Type " + type +
" do not match the hourly rate");
return 0;

}else if (type.equals("P") && !(hourlyRate >= 30 && hourlyRate <= 45)) {


JOptionPane.showMessageDialog(null, "Employee Type " + type +
" do not match the hourly rate");
return 0;

}else if (type.equals("F") && !(hourlyRate >= 35 && hourlyRate <= 50)) {


JOptionPane.showMessageDialog(null, "Employee Type " + type +
" do not match the hourly rate");
return 0;

}else {
return hourlyRate;
}
}

/**
* Validate Hours Worked
* @param hrs
* @return int
*/
public static int validateHrsWorked(String hrs) {
int hrsWorked;
try {
hrsWorked = Integer.parseInt(hrs);
}catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: Hours Worked must
be numeric!");
return 0;
}
if (hrsWorked < 20 || hrsWorked > 60) {
JOptionPane.showMessageDialog(null, "Error: Enter a valid
number for Hours Worked!");
return 0;
}
else {
return hrsWorked;
}
}

10449314 Page |6
CSI3105 SOFTWARE TESTING – Minor 01

/**
* Calculate Weekly Gross Pay
* @param rate
* @param hrs
* @return double
*/
public static double calculateWages(double rate, int hrs) {

double totalWages = rate * hrs;

DecimalFormat df = new DecimalFormat("#.##");


totalWages = Double.valueOf(df.format(totalWages));
return totalWages;

}
}

2. Testing

2.1. Equivalence Partitioning (EP):

2.1.1. Input Domain

Note: Employee Id values are defined as the length of the id.

Variables Types Values

empID Int { 00000 <= 99999 }

empType String { C }, { P }, { F }

hrsWorked Int { 20 <= 60 }

If Employee Type C: { 20 <= 35 }

hourlyRate double If Employee Type P: { 30 <= 45 }

If Employee Type F: { 35 <= 50 }


Table 2: Input Domain

10449314 Page |7
CSI3105 SOFTWARE TESTING – Minor 01

2.1.2. Equivalence Classing

Variables Partition
{
{ empID >= 00000 },
{ 00000 <= empID <= 99999 },
empID
{ empID <= 99999 },
{ invalid_1 }
}
{
empType { C }, { P }, { F }, { invalid_2 }
}
{
{ hrsWorked >= 20 },
{ 20 <= hrsWorked <= 60 },
hrsWorked
{ hrsWorked <= 60 }
{ invalid_3 }
}
{
{
{ hourlyRate >= 20 },
{ 20 <= hourlyRate <= 35 },
{ hourlyRate <= 35 }
},

{
{ hourlyRate >= 30 },
{ 30 <= hourlyRate <= 45 },
hourlyRate { hourlyRate <= 45 }
},

{
{ hourlyRate >= 35},
{ 35 <= hourlyRate <= 50},
{ hourlyRate <= 50}
},

{ invalid_4 }
}
Table 3: Equivalence Classing

10449314 Page |8
CSI3105 SOFTWARE TESTING – Minor 01

2.1.3. Combine Equivalence Classes

There are total of 4 x 4 x 4 x 10 = 640 equivalence classes

2.1.4. Infeasible Equivalence Classes

E1: empID < 00000 E10: hourlyRate < 20


For Emp
E2: empID > 99999 E11: hourlyRate > 35
Type C
E3: 00000 > empID > 99999 E12: 20 > hourlyRate > 35
E4: Invalid_1 (any other string characters) E13: hourlyRate < 30
Invalid_2 (other than C,P,F – For Emp
E5: E14: hourlyRate > 45 Type P
any alphabetic character)
E6: hrsWorked < 20 E15: 30 > hourlyRate > 45
E7: hrsWorked > 60 E16: hourlyRate < 35
For Emp
E8: 20 > hrsWorked > 60 E17: hourlyRate > 50
Type F
E9: Invalid_3 (any float numbers) E18: 35 > hourlyRate > 50
E19: Invalid_4 (any other string characters)
Table 4: Infeasible Equivalence Classes

2.1.5. Weak / Strong Equivalence Class Testing

2.1.5.1. Weak Equivalence Class (WECT)


The idea of weak equivalence class is to identify the testing that is accomplished by using
one variable from each equivalence class in a test case.

Employee Hours
Test Case Employee ID Hourly Rate Output
Type Worked
WECT1 00000 C 20.0 19 Output results
WECT2 99999 P 45.0 20 Output results
WECT3 1234 F 50.0 60 Invalid input
WECT4 a4bc03 X 35.1 61 Invalid input
Table 5: Weak Equivalence Class

10449314 Page |9
CSI3105 SOFTWARE TESTING – Minor 01

2.1.5.2. Strong Equivalence Class (SECT)


According to my Strong Equivalence Class Testing,
the #SECT test cases = (E) x (T) x (RC) x (RP) x (RF) x (H)
= 6 x 5 x 7 x 7 x 8 x 8 = 94,080 Test Cases.
 Strong Equivalence Class testing technique divides the input data into partitions of
equivalence data to develop test cases where test cases are designed to cover each partition
at least once. The idea is to identify test cases by using one element from each equivalence
class. Since I got 94080 test cases, in the following SECT I have only written few.

Test Case Employee ID Employee Type Hourly Rate Hours Worked


SECT1 00000 C 19.9 ERROR
SECT2 00000 C 20.0 20
SECT3 00000 C 35.0 60
SECT4 00000 C 35.1 ERROR
SECT5 99999 C 19.9 ERROR
SECT6 99999 C 20.0 20
SECT7 99999 C 35.0 60
SECT8 99999 C 35.1 ERROR
SECT9 1234 ERROR - -
SECT10 1234 ERROR - -
SECT11 1234 ERROR - -
SECT12 1234 ERROR - -
SECT13 a4bc03 ERROR - -
SECT14 a4bc03 ERROR - -
SECT15 a4bc03 ERROR - -
SECT16 a4bc03 ERROR - -
SECT17 00000 P 29.9 ERROR
SECT18 00000 P 30.0 20
SECT19 00000 P 45.0 60
SECT20 00000 P 45.1 ERROR
SECT21 99999 P 29.9 ERROR
SECT22 99999 P 30.0 20
SECT23 99999 P 45.0 60
SECT24 99999 P 45.1 ERROR
SECT25 00000 F 34.9 ERROR
SECT26 00000 F 35.0 20
SECT27 00000 F 50.0 60
SECT28 00000 F 50.1 ERROR
SECT29 99999 F 34.9 ERROR
SECT30 99999 F 35.0 20
SECT31 99999 F 50.0 60
SECT32 99999 F 50.1 ERROR
SECT33 00000 X ERROR -
SECT34 99999 X ERROR -
Table 6: Strong Equivalence Class

10449314 P a g e | 10
CSI3105 SOFTWARE TESTING – Minor 01

2.2. Boundary Value Analysis (BVA)

2.2.1. Hours Worked

E1: Values less than 20


E2: Values in the range
E3: Values greater than 60

Figure 2: BVA of hours worked

2.2.2. Hourly Rate for Employee Type C

E4: Values less than 20.0


E5: Values in the range
E6: Values greater than 35.0

Figure 3: BVP of hourly rate - type C

10449314 P a g e | 11
CSI3105 SOFTWARE TESTING – Minor 01

2.2.3. Hourly Rate for Employee Type P

E7: Values less than 30.0


E8: Values in the range
E9: Values greater than 45.0

Figure 4: BVP of hourly rate - type P

2.2.4. Hourly Rate for Employee Type F

E10: Values less than 35.0


E11: Values in the range
E12: Values greater than 50.0

Figure 5: BVP of hourly rate - type F

10449314 P a g e | 12
CSI3105 SOFTWARE TESTING – Minor 01

2.3. Test Cases

2.3.1. Function to be tested: validateEmpID

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)

Method returns false.


Invalid length of ID
A-01 [When only 4 digits are EP 1234
Display error message:
entered]
“Error: Enter a 5-digit number!”
Method returns true and
Displays a dialog box
Valid length of ID is “Enter your Employee Type:”
A-02 EP 00000
5-digit numbers
At the end of the program -
Display Output of Employee ID:
“Employee ID: 00000”
Method returns true and
Displays a dialog box
“Enter your Employee Type:”
Valid length of ID is
A-03 EP 10445
5-digit numbers
At the end of the program -
Display Output of Employee ID:
“Employee ID: 10445”
Method returns true and
Displays a dialog box
“Enter your Employee Type:”
Valid length of ID is
A-04 EP 99999
5-digit numbers
At the end of the program -
Display Output of Employee ID:
“Employee ID: 99999”
Method returns false.
Invalid length of ID
A-05 [When only 6-digits are EP 123456
Display error message:
entered]
“Error: Enter a 5-digit number!””

Method returns false.

Invalid Employee ID
A-06 EP a4bc0 Display error message:
[When a string is entered]
“Error: Employee ID must contain
only numbers!”
Table 7: Test case for Employee ID

10449314 P a g e | 13
CSI3105 SOFTWARE TESTING – Minor 01

2.3.2. Function to be tested: validateEmpType

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)

Method returns true and


Valid characters for Displays a dialog box
Employee Type are C,P,F “Enter your hourly rate:”
B-01 EP C
[When a character ‘C’ is At the end of the program -
entered] Displays Output of Employee Type:
“Employee Type: C”

Method returns true and


Valid characters for Displays a dialog box
Employee Types are C,P,F “Enter your hourly rate:”
B-02 EP P
[When a character ‘P’ is At the end of the program -
entered] Displays Output of Employee Type:
“Employee Type: P”

Method returns true and


Valid characters for Displays a dialog box
Employee Types are C,P,F “Enter your hourly rate:”
B-03 EP F
[When a character ‘F’ is At the end of the program -
entered] Displays Output of Employee Type:
“Employee Type: F”

Invalid Employee Type Method returns false.


B-04 [When a character ‘X’ is EP X Displays error message:
entered] “Error: Enter a valid Employee Type!”
Table 8: Test case for Employee Type

10449314 P a g e | 14
CSI3105 SOFTWARE TESTING – Minor 01

2.3.3. Function to be tested: validateHourlyRate for Employee Type C

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-01 BVP 19.9 Displays error message:
boundary value (20) is
“Error: Employee Type C do not
entered]
match the hourly rate“
Given that Employee type is C
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-02 $20.00 and $35.00. BVP 20.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 20]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-03 BVP 20.1
boundary value (20) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-04 [Any value within the range of EP 25.4
“Enter your worked hours for this
20 and 35 is entered]
week:”
Valid value of hourly rate. Method returns true and
[Lowest boundary value near Displays a dialog box
C-05 BVP 34.9
boundary value (35) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-06 [Second boundary value of BVP 35.0
“Enter your worked hours for this
hourly rate is 35]
week:”
Method returns false.
Invalid value of hourly rate.
[Highest boundary value near
C-07 BVP 35.1 Displays error message:
boundary value (35) is
“Error: Employee Type C do not
entered]
match the hourly rate”
Table 9: Test case for hourly rate - type C

10449314 P a g e | 15
CSI3105 SOFTWARE TESTING – Minor 01

2.3.4. Function to be tested: validateHourlyRate for Employee Type P

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-08 BVP 29.9 Displays error message:
boundary value (30) is
“Error: Employee Type P do not
entered]
match the hourly rate”
Given that Employee type is P
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-09 $30.00 and $45.00. BVP 30.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 30]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-10 BVP 30.1
boundary value (30) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-11 [Any value within the range of EP 40.4
“Enter your worked hours for this
30 and 45 is entered]
week:”
Valid value of hourly rate. Method returns true and
[Lowest boundary value near Displays a dialog box
C-12 BVP 44.9
boundary value (45) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-13 [Second boundary value of BVP 45.0
“Enter your worked hours for this
hourly rate is 45]
week:”
Method returns false.
Invalid value of hourly rate.
[Highest boundary value near
C-14 BVP 45.1 Displays error message:
boundary value (45) is
“Error: Employee Type P do not
entered]
match the hourly rate”
Table 10: Test case for hourly rate - type P

10449314 P a g e | 16
CSI3105 SOFTWARE TESTING – Minor 01

2.3.5. Function to be tested: validateHourlyRate for Employee Type F

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-15 BVP 34.9 Displays error message:
boundary value (35) is
“Error: Employee Type F do not
entered]
match the hourly rate”
Given that Employee type is F
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-16 $35.00 and $50.00. BVP 35.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 35]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-17 BVP 35.1
boundary value (35) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-18 [Any value within the range of EP 46.8
“Enter your worked hours for this
35.00 and 50.00 is entered]
week:”
Valid value of hourly rate. Method returns true and
[Lowest boundary value near Displays a dialog box
C-19 BVP 49.9
boundary value (50) is “Enter your worked hours for this
entered] week:”

Valid value of hourly rate. Method returns true and


Displays a dialog box
C-20 [Second boundary value of BVP 50.0
“Enter your worked hours for this
hourly rate is 50]
week:”
Method returns false.
Invalid value of hourly rate.
[Highest boundary value near
C-21 BVP 50.1 Displays error message:
boundary value (50) is
“Error: Employee Type F do not
entered]
match the hourly rate”

Method returns false.


C-22 Invalid value of hourly rate. E 4gh*& Displays error message:
“Hourly Rate must be numeric!”

Table 11: Test case for hourly rate - type F

10449314 P a g e | 17
CSI3105 SOFTWARE TESTING – Minor 01

2.3.6. Function to be tested: validateHrsWorked

Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVA)
Method returns false.
Invalid value of hours worked.
[Lowest boundary value near
D-01 BVA 19 Displays error message:
boundary value (20) is
“Error: Enter a valid number for
entered]
Hours Worked!”
Valid range of hours worked is Method returns true.
20 and 60 hours.
D-02 BVA 20 At the end of the program -
[First boundary value of hours
Displays Output of Hours Worked:
worked is 20] “Hours Worked: 20 hours”
Method returns true.
Valid value of hours worked.
D-03 [Highest boundary value near BVA 21 At the end of the program -
boundary value is entered] Displays Output of Hours Worked:
“Hours Worked: 21 hours”
Method returns true.
Valid value of hours worked.
D-04 [Any value within the range is EP 46 At the end of the program -
entered] Displays Output of Hours Worked:
“Hours Worked: 46 hours”
Valid value of hours worked. Method returns true.
[Lowest boundary value near
D-05 BVA 59 At the end of the program -
boundary value (60) is
Displays Output of Hours Worked:
entered] “Hours Worked: 59 hours”
Method returns true.
Valid value of hours worked.
D-06 [Second boundary value of BVA 60 At the end of the program -
hours worked is 60] Displays Output of Hours Worked:
“Hours Worked: 60 hours”
Method returns false.
Invalid value of hours worked.
[Highest boundary value near
D-07 BVA 61 Displays error message:
boundary value (60) is
“Error: Enter a valid number for
entered]
Hours Worked!”
Method returns false.
Displays error message:
D-08 Invalid value of hours worked. E 25.6
“Error: Hours Worked must be a
real number!”
Table 12: Test case for hours worked

10449314 P a g e | 18
CSI3105 SOFTWARE TESTING – Minor 01

2.4. JUnit
JUnit is an open source testing framework created for the purpose of writing and running
tests in the Java programming language and one of the features of JUnit is that it provides
assertions for testing expected results and also provides annotations to identify test methods.
As for the Payroll Program, the following are the tests for the methods of Employee ID,
Employee Type, Hourly Rate (Types C,P,F), Hours Worked:

2.4.1. Employee ID Test

import static org.junit.Assert.*;


import org.junit.Test;

public class EmployeeIDTest {

/**
* Test values in Employee Id
*/
@Test
public void testEmpIDPass() {

assertEquals("error in EmpID()", "00000", PayrollProgram.validateEmpID("00000")); // A-02


assertEquals("error in EmpID()", "10445", PayrollProgram.validateEmpID("10445")); // A-03
assertEquals("error in EmpID()", "99999", PayrollProgram.validateEmpID("99999")); // A-04
}

@Test
public void testEmpIDFail() {

assertNotEquals("error in EmpID()", "1234", PayrollProgram.validateEmpID("1234"));// A-01


assertNotEquals("error in EmpID()", "123456", PayrollProgram.validateEmpID("123456"));// A-02
}

/**
* Test Employee Id's data type
*/
@Test
public void testEmpIDInvalid() {

assertNotEquals("Invalid Emp ID", "a4bc0", PayrollProgram.validateEmpID("a4bc0")); // A-06


}
}

10449314 P a g e | 19
CSI3105 SOFTWARE TESTING – Minor 01

2.4.2. Employee Type Test

import static org.junit.Assert.*;


import org.junit.Test;

public class EmployeeTypeTest {

/**
* Test Employee Types of C, P, F
*/
@Test
public void testEmpTypePass() {
assertEquals("error in EmpType()", "C", PayrollProgram.validateEmpType("C")); // B-01
assertEquals("error in EmpType()", "P", PayrollProgram.validateEmpType("P")); // B-02
assertEquals("error in EmpType()", "F", PayrollProgram.validateEmpType("F")); // B-03
}

@Test
public void testEmpTypeFail() {
assertNotEquals("Invalid Emp Type", "X", PayrollProgram.validateEmpType("X")); // B-04
}
}

2.4.3. Hourly Rate Test

import static org.junit.Assert.*;


import org.junit.Test;

public class HourlyRateTest {

/**
* Test hrly rate for Employee Type C between $20.0 - $35.0
*/
@Test
public void testPassTypeC() {

assertEquals("error in hrlyRate()", 20.0, PayrollProgram.validateHourlyRate("C", "20.0"), 0); //C-02


assertEquals("error in hrlyRate()", 20.1, PayrollProgram.validateHourlyRate("C", "20.1"), 0); //C-03
assertEquals("error in hrlyRate()", 25.4, PayrollProgram.validateHourlyRate("C", "25.4"), 0); //C-04
assertEquals("error in hrlyRate()", 34.9, PayrollProgram.validateHourlyRate("C", "34.9"), 0); //C-05
assertEquals("error in hrlyRate()", 35.0, PayrollProgram.validateHourlyRate("C", "35.0"), 0); //C-06
}

@Test
public void testFailTypeC() {

assertNotEquals("error in hrlyRate()", 19.0, PayrollProgram.validateHourlyRate("C", "19.0")); //C-01


assertNotEquals("error in hrlyRate()", 35.1, PayrollProgram.validateHourlyRate("C", "35.1")); //C-07
}

10449314 P a g e | 20
CSI3105 SOFTWARE TESTING – Minor 01

/**
* Test hourly rate for Employee Type P between $30.0 - $45.0
*/
@Test
public void testPassTypeP() {

assertEquals("error in hrlyRate()", 30.0, PayrollProgram.validateHourlyRate("P", "30.0"), 0); //C-09


assertEquals("error in hrlyRate()", 30.1, PayrollProgram.validateHourlyRate("P", "30.1"), 0); //C-10
assertEquals("error in hrlyRate()", 40.4, PayrollProgram.validateHourlyRate("P", "40.4"), 0); //C-11
assertEquals("error in hrlyRate()", 44.9, PayrollProgram.validateHourlyRate("P", "44.9"), 0); //C-12
assertEquals("error in hrlyRate()", 45.0, PayrollProgram.validateHourlyRate("P", "45.0"), 0); //C-13
}

@Test
public void testFailTypeP() {

assertNotEquals("error in hrlyRate()", 29.9, PayrollProgram.validateHourlyRate("P", "29.9")); //C-08


assertNotEquals("error in hrlyRate()", 45.1, PayrollProgram.validateHourlyRate("P", "45.1")); //C-14
}

/**
* Test hourly rate for Employee Type F between $35.0 - $50.0
*/
@Test
public void testPassTypeF() {

assertEquals("error in hrlyRate()", 35.0, PayrollProgram.validateHourlyRate("F", "35.0"), 0); //C-16


assertEquals("error in hrlyRate()", 35.1, PayrollProgram.validateHourlyRate("F", "35.1"), 0); //C-17
assertEquals("error in hrlyRate()", 46.8, PayrollProgram.validateHourlyRate("F", "46.8"), 0); //C-18
assertEquals("error in hrlyRate()", 49.9, PayrollProgram.validateHourlyRate("F", "49.9"), 0); //C-19
assertEquals("error in hrlyRate()", 50.0, PayrollProgram.validateHourlyRate("F", "50.0"), 0); //C-20
}

@Test
public void testFailTypeF() {

assertNotEquals("error in hrlyRate()", 34.9, PayrollProgram.validateHourlyRate("F", "34.9")); // C-15


assertNotEquals("error in hrlyRate()", 50.1, PayrollProgram.validateHourlyRate("F", "50.1")); // C-21

/**
* Test hourly rate data type
*/
@Test
public void testHrlyRateInvalid() {

assertNotEquals("error in hrlyRate()", "4gh*&", PayrollProgram.validateHourlyRate("F", "4gh*&"));


// C-22
}
}

10449314 P a g e | 21
CSI3105 SOFTWARE TESTING – Minor 01

2.4.4. Hours Worked Test

import static org.junit.Assert.*;


import org.junit.Test;

public class HoursWorkedTest {

/**
* Test values for hours worked between 20 - 60 hours
*/
@Test
public void testHrsWrkPass() {

assertEquals("error in hrsWrk()", 20, PayrollProgram.validateHrsWorked("20")); // D-02


assertEquals("error in hrsWrk()", 21, PayrollProgram.validateHrsWorked("21")); // D-03
assertEquals("error in hrsWrk()", 46, PayrollProgram.validateHrsWorked("46")); // D-04
assertEquals("error in hrsWrk()", 59, PayrollProgram.validateHrsWorked("59")); // D-05
assertEquals("error in hrsWrk()", 60, PayrollProgram.validateHrsWorked("60")); // D-06
}

@Test
public void testHrsWrkFail() {

assertNotEquals("error in hrsWrk()", 19, PayrollProgram.validateHrsWorked("19")); // D-01


assertNotEquals("error in hrsWrk()", 61, PayrollProgram.validateHrsWorked("61")); // D-07
}

/**
* Test hours worked data type
*/
@Test
public void testHrsWrkInvalid() {

assertNotEquals("error in hrsWrk()", 25.6, PayrollProgram.validateHrsWorked("25.6")); //D-08


}
}

10449314 P a g e | 22
CSI3105 SOFTWARE TESTING – Minor 01

Appendix
1. Screenshots

1.1. JUnit

Figure 6: JUnit Tests Screenshot

10449314 P a g e | 23
CSI3105 SOFTWARE TESTING – Minor 01

Figure 7: JUnit execution on All Tests

10449314 P a g e | 24
CSI3105 SOFTWARE TESTING – Minor 01

1.2. Employee ID

1.3. Employee Type

1.4. Hourly Rate for Employee Type C

10449314 P a g e | 25
CSI3105 SOFTWARE TESTING – Minor 01

1.5. Hourly Rate for Employee Type P

1.6. Hourly Rate for Employee Type F

10449314 P a g e | 26
CSI3105 SOFTWARE TESTING – Minor 01

1.7. Hours Worked

1.8. Outputs the Results of Payroll Program

10449314 P a g e | 27

You might also like