Discuss why we need both mocking and stubbing instead

Assignment Help Software Engineering
Reference no: EM133673725

Task: Integration testing by mocking and stubbing dependencies

Overview
Integration testing, specifically the top­down approach, requires mocking (or stubbing) leaf modules down in the hierarchy to test the functionality of a higher­level 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 pre­defined 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 - top­down and bottom­up 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 family­doctor 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 35­37
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.

Reference no: EM133673725

Questions Cloud

Integrate web front­end with java api : Integrate web front­end with Java API back end as part of integration testing - Development of front and back ends may progress separately
Describe the qualities that you think are most important : Describe the qualities that you think are most important for someone to be recognized as a conscious leader. How to develop the qualities you described above.
Programmer uses algorithm : A programmer uses an algorithm that will determine if a number is odd or even using modulus.
What are three virtues that you think are most important : What are two or three virtues that you think are most important in our personal lives and in our business affairs and explain why you selected those?
Discuss why we need both mocking and stubbing instead : Integration testing by mocking and stubbing dependencies - Discuss why we need both mocking and stubbing instead of any one of them with proper references
Create two separate functions satisfying both the conditions : Create two separate functions satisfying both the conditions of part B - (a) a loop with simple statement and (b) a loop with conditional statement
Explain the potential negative impacts on the company : Identify one of the 8 waste listed in the article and provide an example from a service industry company. Explain the potential negative impacts on the company.
Focus on basic SQL queries : This assignment will focus on basic SQL queries. The dataset on which you will execute the queries has been provided as SQL scripts.
Difference between persistence time and test function : Come up with an idea including stopping the clock or fake the clock so that the unit test runs successfully all the time

Reviews

Write a Review

Software Engineering Questions & Answers

  Research report on software design

Write a Research Report on software design and answer diffrent type of questions related to design. Report contain diffrent basic questions related to software design.

  A case study in c to java conversion and extensibility

A Case Study in C to Java Conversion and Extensibility

  Create a structural model

Structural modeling is a different view of the same system that you analyzed from a functional perspective. This model shows how data is organized within the system.

  Write an report on a significant software security

Write an report on a significant software security

  Development of a small software system

Analysis, design and development of a small software system.

  Systems analysis and design requirements

Systems Analysis and Design requirements

  Create a complete limited entry decision table

Create a complete limited entry decision table

  Explain flow boundaries map

Explain flow boundaries map the dfd into a software architecture using transform mapping.

  Frame diagrams

Prepare a frame diagram for the software systems.

  Identified systems and elements of the sap system

Identify computing devices, which could be used to support Your Improved Process

  Design a wireframe prototype

Design a wireframe prototype to meet the needs of the personas and requirements.

  Explain the characteristics of visual studio 2005

Explain the characteristics of Visual Studio 2005.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd