Identify use cases where some of these unit testing

Assignment Help Software Engineering
Reference no: EM133673717

Task - Unit test standards - AAA and [F]IRST

Overview
Unit tests provide many significant benefits when crafted with care. There are best practices of unit testing covered this week which talks about how tests can be organised such as AAA (Arrange, Act, Assert, After) or properties of good tests such as FIRST (Fast, Isolated, Repeatable, Self­validating, Timely). In this task a WeatherControllerTest class has been provided to test 3 functions of WeatherController. WeatherController stores today's hourly temperature values and calculates minimum, maximum and average of hourly temperature values and stores in cache for faster access. There is a function in WeatherController to query temperature for a given hour which is a slow operation, also, the WeatherController initialisation and shutdown operations are also slow process. You will need to follow AAA standard to organise 3 tests in WeatherControllerTest so that the Fast property of FIRST principle can be achieved. Identify use cases where following some of these unit testing standards are difficult to follow and recommendation with references from research articles or corporate blog posts.

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 task5_1P.zip which contains WeatherController.java and its test cases in WeatherControllerTest.java. You update the WeatherControllerTest.java file as required.
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) Eclipse console which shows outputs.
Your program's source code for tests (WeatherControllerTest.java)
With proper references, identify use cases where unit testing standards are difficult to follow while creating test cases and possible work arounds.
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.
Keep tests consistent with AAA
FIRST properties of good tests
JUnit's support for AAA.

Instructions
For this task you will need to
Download task5_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 WeatherController class structure in WeatherController.java file which contains today's hourly temperature values, currently 3 hours per day is set (see the HOURS_PER_DAY=3 field to increase number of hours up to 24, if needed). Member functions are summarised in the table below.

Functions Details
getTemperatureMinFromCache Cached statistics
getTemperatureMaxFromCache Cached statistics
getTemperatureAverageFromCache Cached statistics
getTemperatureForHour Retrieves temperature value for the queried
hour, slower response
persistTemperature Stores reported temperature value for the specified hour, it returns persistence
timestamp.

getTotalHours Number of hours temperature values are persisted (currently 3, controlled by the
constant HOURS_PER_DAY).
getInstance() and close() Slow responding functions to create and
destroy WeatherController class object.

One of the cache functions and the slow process of interest getTemperatureForHour() are shown below. As you can see, getTemperatureForHour

To keep things simple, the temperature values are randomly initialised in the constructor function during creation of WeatherController object instead of reading directly from sensors. This means, when the getInstance() is called for the first time or after calling the close() method, the WeatherController constructor executes and random temperature values are initialised.

A test function in WeatherControllerTest.java to test the cached minimum temperature value is shown below. The test function's body contains code to initialise the WeatherController, retrieves all the temperature values from controller by using the slow responding function getTemperatureForHour(int hour) for all the available hours in the controller. Compares the calculated minimum value with the controller's cached minimum value. Finally, it closes the controller.

The other 2 test functions testTemperatureMax() and testTemperatureAverage() share similar code structure. Note that the function testTemperaturePersist() is commented which is above Pass task and does not require for 5.1P task to change the function, you can leave it as it is.

If you run one of these tests, you will notice each of them takes more than 10 seconds. You restructure these 3 tests so that the tests can run as fast as possible. You can adopt techniques such as separating common initialisation and shutdown functions from the main test function; instead of querying hourly temperature values for each test, store them locally so they can be reused across these tests. If you consider reusing WeatherController function's getInstance() across test functions, keep in mind not to call close() function which will create a new instance and a new random set of temperature values will be initialised and eventually WeatherController's cached functions (min, max or average temperatures) will show different values. It is advised to study the behavior of WeatherController in case of any confusion.
There are 2 test failures that you need to correct by providing your name and id in the first 2 test cases.
Run the test, take screenshot of test statistic and the console output.
Upload your folder to your GitHub account and take a screenshot.

Your Task
Your task is to:
Study WeatherController.java to understand the member functions of the controller as outlined in a table above.
Study WeatherControllerTest.java to understand the 3 test cases (all but the testTemperaturePersist for this task). They share some common codes in addition to the main test logic.
Run these tests and observe the time taken to complete these tests.

You need to restructure the tests using AAA standards so these tests can run faster.

Reference no: EM133673717

Questions Cloud

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
Comment out the method calls : It is now your task to write the methods that this program uses. Comment out the method calls until you are ready to use them,
Explain how you determine the initial cash flows : Explain how you determine the initial cash flows. Discuss the notion of sunk costs and identify the sunk cost in this project.
Azure directory connect : You are required to install Azure Directory Connect. You can either use custom settings or express settings for the installation process.
Identify use cases where some of these unit testing : Task - Unit test standards – AAA and [F]IRST - Identify use cases where some of these unit testing standards are difficult
What are some of the reasons that foreign manufacturers : What are some of the reasons that foreign manufacturers of products as diverse as automobiles, cell phones and tires might arrive at the same conclusion.
Concepts and field of systems analysis and design : How did this course assist you in better understanding the concepts and field of systems analysis and design?
Implement test cases using selenium browser automation : Analyse the webpages source to identify the login HTML elements and how to locate them using Selenium APIs. Implement test cases using Selenium browser
What is interned string object used : What is an interned string object used for? Suppose you have a text file containing the string ABCDEFGH.

Reviews

Write a Review

Software Engineering Questions & Answers

  The global pharmaceutical industry - in the land of

the global pharmaceutical industry - in the land of shrinking giants.1. introductionthe case describes the evolution of

  What is the correct html and css code to design

What is the correct HTML and CSS code to design the page below? The navigation section should remain to the left of the text, regardless of the browser viewport

  How the paint defect statistics have changed over the course

A summary of how the paint defect statistics have changed over the course of a week at a given GM plant. The report emphasizes defects per surface.

  List of three pros and three cons of test automation

The Director of Software Engineering wants you to provide some insights into test automation. The company is trying to include as much software testing.

  Discuss the different types of SDLC methodology

SMB4201 Systems Analysis and Design Assignment, Asia Pacific international college, Australia. Discuss the different types of SDLC methodology

  Draw an erd for the autoparts warehouse indicating the

autoparts warehouse is a small auto parts supplier with locations in several midwestern metro areas. the business is

  Create a detailed class design for two of your classes

Use CASE tool to create a detailed class design for two of your classes. Discuss the use cases, detailed class design(attributed, operations, and algorithms)and sequence diagram used for your class design decisions.

  Software tools for managing and analyzing qualitative data

Craft a 3- page paper and 5 references in which you do the following: Compare and contrast software tools for managing and analyzing qualitative data

  Create a wbs and enter the tasks in project.

Create a WBS and enter the tasks in Project. Be sure to include milestones, summary tasks and an extensive set of subtasks. Include all dependencies.

  Create a challenge for forensic experts during the analysis

There are multiple information-hiding methods available to conceal evidence on victim systems which consequently create a challenge for forensic experts

  Produce a state diagram to illustrate the expected behavior

Produce a state diagram to illustrate the expected behavior of the key domain object - Perform UCR for the normal flows of both use cases and produce summary analysis class diagrams that encapsulate the requirements for both use cases.

  Analysis of a large system development problem

Analyse and apply complex decision making to determine the appropriate methodology to apply to different development situations - Develop a good understanding of processes to ensure quality in the engineering of large software systems

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