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”.
b. If the total of any two sides are less than or equal the third side, then method returns “Not” meaning that the given sides do not form a triangle. (If a + b <= c returns not). c. If none of the two conditions above are met, then i. If a, b and c are all equal method returns "Equilateral". ii. If any of the two inputs are equal method returns "Isosceles". iii. If all sides are different method returns "Scalene". 2. adjustSides: This method returns a double number for a given integer input. Specifications of the method as follows: a. If given input is 1≤ input ≤ 50 it returns a double with the same input value. b. If given input is greater than 50 it returns 1.234input (1.234 to the power of the input). For example, if number is 70 return value will be (1.234)70. c. If given value if 0 or less, it returns negative of the input number. For example, if number is -1 return value is 1). Due to the return values being too high for some inputs you can use “Double.POSITIVE_INFINITY” as your expected output when performing boundary value analysis. 5. Black Box Testing • Clone repository https://github.research.its.qmul.ac.uk/eew954/Lab8.git • Create a new NetBeans project called Lab8 with existing files from the cloned repository. Your project folder should look like below. • Identify the equivalence partitions for both checkType and adjustSides functions based on the specifications given on the previous page. • Create the test cases to perform boundary testing on the identified partition as described on the previous page. • Test the two Java methods in Triangle class with the test cases you created to reveal existing defects. • It is recommended that you use JUnit for testing however you can write your own driver methods to run the test cases if you want. An example code is included in TriangleTest file. • Enter your test inputs and expected and observed results in the test report document. 6. Branch and Path Coverage Suppose you are asked to test the following Java method. • List the minimum amount of test cases that will cover all branches. • List all paths in this code including the infeasible ones. • List the minimum amount of test cases that will cover all feasible paths. • Did any of test suites that executes of all paths or the feasible paths reveal any defects? • Enter your test cases and results in the test report document. Make sure to add the three libraries in the lib folder (cloned) to your project if they don’t appear in your project. You also need to add JUnit and Hamcrest libraries under test libraries. public int verifyMessageLength(char[] content){ int length = content.length; if(length > 10)
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
Order Now

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
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?