Reference no: EM133673725
Task: Integration testing by mocking and stubbing dependencies
Overview
Integration testing, specifically the topdown approach, requires mocking (or stubbing) leaf modules down in the hierarchy to test the functionality of a higherlevel module. In this task BodyTemperatureMonitor.java is created which depends on three dependent modules including TemperatureSensor.java, CloudService.java and NotificationSender.java. You will need to write test codes for predefined JUnit test functions in BodyTemperatureMonitorTest.java to achieve above 90% code coverage. You may need to mock or stub the dependent modules to test BodyTemperatureMonitorTest.java. Discuss why we need both mocking and stubbing instead of any one of them with proper references; find use cases from Deakin's internal websites such as unit site, OnTrack or any other.
Submission details
Use the instructions on the following page to carry out this task's steps.
For this task you will need to study the existing project task7_2P.zip which contains source and test files in sit707_week7 package in corresponding source and test folders in Eclipse project. The test subpackage sit707_week7.sample contains an example on how to use mocks and stubs and perform unit tests. You need to update the test java file as required, use mocks and stubs and achieve above 90% code coverage.
Submit a pdf combining below items
A screenshot of your Eclipse IDE's (i) JUnit tab which shows test statistics including Runs, Errors and Failures and (ii) Emma coverage output which shows coverage statistics including percentage coverage per java file and corresponding number of instructions covered/missed.
Your program's source code for tests BodyTemperatureMonitorTest.java
Comparative analysis between mocking and stubbing with use cases drawn from Deakin's internal websites.
A screenshot of your github page where your latest project folder is pushed.
You want to focus on the following key ideas, and make sure you can explain them in relation to your program.
Integration testing - topdown and bottomup approach.
Mocking and stubbing in the context of integration tests - where to use what.
Instructions
For this task you will need to
Download task7_1P.zip Java project and unzip it in a common folder (say, java_projects) which you will be using to store all the weekly projects.
Import the project (as a maven project) in Eclipse IDE.
Observe java files in package sit707_week7.sample in test folder which has a single java test file StudentReaderTest.java with below test functions. These test functions used classes and methods defined in java files in the same sit707_week7.sample package in source folder.
testFindStudent() Stubs StudentRepository class to test
StudentReader.findFullName() function.
testStudentRepoSave() Stubs StudentRepository class to test
StudentReader.createNew() function.
testEmailSend() Mocks EmailSender.sendEmail() function that it is
called once by StudentReader.notifyStudent() function.
testEmailNoSend() A version of testEmailSend() above where mock
sendEmail() is never called by StudentReader.
The BodyTemperatureMonitor.java file is the source that you need to test. This file contains below member attributes and functions.
Member attributes Description
TemperatureSensor temperatureSensor Dependency module to be mocked
NotificationSender notificationSener Dependency module to be mocked
CloudService cloudService Dependency module to be mocked
Member Functions
BodyTemperatureMonitor(TemperatureSens
or, CloudService, NotificationSender) Constructor which takes 3 dependencies as
parameters.
readTemperature() Calls readTemperatureValue() of
temperatureSensor module.
reportTemperatureReadingToCloud() Calls sendTemperatureToCloud() of
cloudService module.
InquireBodyStatus() Calls queryCustomerBodyStatus() of cloudService and receives either NORMAL or ABNORMAL status. In former status email notification to user is sent but an emergency notification to familydoctor is sent for the
later status condition.
A test file BodyTemperatureMonitorTest.java in test package sit707_week7 contains failed test cases which you will need to fill in with codes and make them pass. The test functions are listed below.
testReadTemperatureNegative() Stub temperatureSensor to return
negative temperature reading.
TestReadTemperatureZero() Stub temperatureSensor to return 0
temperature reading.
TestReadTemperatureNormal() Stub temperatureSensor to return temperature reading between 3537
degree celcius.
TestReadTemperatureAbnormallyHigh() Stub temperatureSensor to return
abnormally high value.
TestReportTemperatureReadingToCloud() Mock cloudService so it's sendTemperatureToCloud is called
once.
TestInquireBodyStatusNormalNotification() Stub cloudService queryCustomerBodyStatus to return status NORMAL so can mock
notificationSender's
sendEmailNotification(Customer)
method.
TestInquireBodyStatusAbnormalNotification() Stub cloudService queryCustomerBodyStatus to return status ABNORMAL so can mock notificationSender's sendEmailNotification(FamilyDoctor)
method.
There are 2 test failures that you need to correct by providing your name and id in the first 2 test cases.
Make sure you achieve above 90% code coverage for BodyTemperatureMonitor.java and its test file.
Run the test, take screenshot of code coverage statistic.
Upload your folder to your GitHub account and take a screenshot.
Your Task
Your task is to:
Study sample package sit707_week7.sample in source and test folder to understand StudentReader.java and how the test file StudentReaderTest.java uses mocks and stubs to test the StudentReader.
Now study BodyTemperatureMonitor.java class attributes and functions which you will need to test. It contains dependencies as member attributes which you need to mock or stub to pass the tests in BodyTemperatureMonitorTest.java test file.
Run the test file Coverage As > JUnit Test to see the coverage output and code highlight.
Try to achieve above 90% code coverage at the source and test java file.