# Software Engineering

ECS505U Software Engineering
Laboratory Exercise (Assessed, 4% of final mark)
Software Testing and Test-Driven Development
Version 1.5, 29/11/2019
1. Background
In a brief overview of the assignment you will be required to test a program by applying some of the techniques discusses during the Software Testing (Week 9) lecture.
2. Prerequisites
• You should be able to run NetBeans on an ITL machine under Windows, or Linux. NetBeans version 8.2 and up is installed on the ITL machines for campus students. Non-campus students should check the SE web page for instructions (the “Using the NetBeans Environment” link is the one you need).
• You should have gone through the lecture slides of week 9.
3. Black-box Testing
In this exercise, you are given a class (Triangle) in a jar file without the access to its implementation details. You are expected to perform black box testing techniques discussed in the lecture to reveal any defects. The required techniques are equivalence portioning and boundary value analysis.
Equivalence partitioning (also called Equivalence Class Partitioning) is a software testing technique that divides the input data of a software unit into partitions of equivalent data from which test cases can be derived.
Figure 1: Example Java function
For the code above equivalence partitions are the inputs that causes the software to exhibit the same behavior.
1. For the first if statement, all possible int values (-231 to 231 -1) where a is equal to b
For example, a is 5 and b is 5
2. For the second if statement, all possible int values where a is greater than b
For example, a is 5 and b is 3
3. For the else statement, all possible int values where a is less than b
For example, a is 4 and b is 6
Boundary testing or boundary value analysis is where test cases are generated using the extremes of the input domain, e.g. maximum, minimum, just inside/outside boundaries, typical values, and error values. It is like Equivalence Partitioning but focuses on “corner cases”.
For the code above equivalence class are three:
1. Month is between 1 and 12. Boundary test for this class is
a. Inside min input 1 and max input 12
b. Outside min input 0 and max input 13
2. Month is less than 1(to -231)
a. Inside min input -231
b. Outside min input not possible since it’s less than min number capacity of integer
c. Inside max input 1
d. Outside max input 0
3. Month is greater than 12 (to 231-1)
a. Inside min input 13
b. Outside min input 12
c. Inside max input 231-1
d. Outside max input not possible since it’s more than max number capacity of integer
In order to perform boundary analysis, we only need to test the code with the following inputs: -231,0,1,12,13 and 231-1.
4. Triangle Class
Triangle class has two methods:
1. checkType: This method returns the type of triangle for a given three side values (integers). It has three input parameters representing the length of three sides of the triangle and returns a string. Specifications of the method as follows:
a. If any of the input parameters (a, b and c) is less than or equal to 0 then method returns the string “Error”.
return 0;
if(length > 1)
return 1;
if(length == 0)
return -1;
}
7. Challenging Branch Coverage
In this part of the exercise, you are expected to find the test suite (with minimum number of test cases) that covers all branches in the code included in the BranchCoverageSourceCode.java file.
The file BranchCoverageSourceCode.java includes the source code for a small code with few branches. BlackBox.jar includes a class called “BranchCoverage” which is an instrumented version of the code in the BranchCoverageSourceCode.java. The instrumented code calculates the coverage of the provided test suite after test runs and provide the coverage score with getCoverage method.
You can use the example Junit test code in the BranchCoverageTest.java file to test your code. When finished, add your test cases and coverage result in the test report document.
HINT: I recommend performing mental execution (on paper) to find out the branches covered by your inputs. Integer inputs between -2 and 10 should be enough to cover all branches. You can also instrument the code under test (add instrumentation code to give you the branches covered) and find out the covered branches.
8. Test Driven Development Exercise
• Complete the code in TemperatureConverter class to pass all the unit tests in TemperatureConverterTest. The specifications of the class given below.
• Add the completed source code of TemperatureConverter class to the report document and submit the file when finished.
TemperatureConverter class is used for converting temperatures and it converts between Celsius, Fahrenheit and Kelvin temperatures. The class uses the formulas below for conversion.
From
To Fahrenheit
To Celsius
To Kelvin
Fahrenheit (F)
F
(F – 32) / 1.8
(F + 459.67) / 1.8
Celsius (C)
(C * 1.8) + 32
C
C + 273.15
Kelvin (K)
(K * 1.8) – 459.67
K – 273.15
K
For each temperature conversion the class has a method such as K2C which converts given Kelvin temperature to Celsius and F2K which converts given Fahrenheit temperature to Kelvin.
The class converts temperatures between min and max values (inclusive) given below. If a temperature outside these limits is provided the conversion method throws an illegal argument exception.
Temp
Max
Min
Fahrenheit (F)
9900000000032
– 459.67
Celsius (C)
5500000000000
– 273.15
Kelvin (K)
5500000000273.15
Class provides these max and min limits statically without needing to create an instance

### Calculate a fair price for your paper

Such a cheap price for your free time and healthy sleep

1650 words
-
Place an order within a couple of minutes.
Get guaranteed assistance and 100% confidentiality.
Total price: \$78
We offer 