Describe the basic concepts and techniques of unit testing

Assignment Help JAVA Programming
Reference no: EM132243502

Data Structures And Object Oriented Programming Assignment - JUnit in Eclipse and Recursion Lab

Part 1 - Creating Unit Test Plans

The first part of this lab involves analyzing the requirements and the design for a method and completing a test plan for it. Unit testing requires an understanding of the what the unit should accomplish and what results should be obtained from a correctly implemented unit.

After completing this exercise, you will be able to:

  • Describe the basic concepts and techniques of unit testing.
  • Analyze the requirements and design of a software unit in order to create a test plan for the unit.

Suppose you are part of a team developing a software unit that will convert an un-signed 16-bit binary number (in string format) to a Java int value. For example, the method binaryToDecimal does the following:

binaryToDecimal ("0000000000000") returns 0

binaryToDecimal ("0000000000001111") returns 15

binaryToDecimal ("0000010000000000") returns 1024

binaryToDecimal ("1111111111111111") returns 65535

Recall that a test case consists of an input value, an expected value and a comment about what is being tested. For the examples shown above the test cases might look like this:

Unit Tests for binaryToDecimal Method

Test #

Input

Expected Output

Test Condition

1

0000000000000

0

Test all 0s

2

0000000000001111

15

Test odd number

3

0000010000000000

1024

Test even number

4

1111111111111111

65535

Test all 1s

Unit Tests for decimalToBinary Method

Test #

Input

Expected Output

Test Condition

1

 

 

 

2

 

 

 

3

 

 

 

4

 

 

 

In addition, another method exists that will convert an int (in base 10) to a binary number represented as a String. What are some test cases that you would write to test this method? Write them out in a table format.

Part 2 - Unit Testing in Eclipse

Create a new Eclipse project called Lab6. Add the JUnit4 Library to your project as you did for last week's lab.

Suppose that another programmer has implemented these methods in a utility class called BinString and you are responsible for testing it. Download BinString.java from Blackboard import it into a your Lab6 project. For the first part of the lab, you will create a JUnit test class for the BinString class.

To create a test class:

1. Select the menu options File > New > JUnit Test Case.

2. Click on the radio button New JUnit 4 test.

3. Type BinStringTest for the class name if the wizard does not automatically create this name.

4. Check that the Class under test: is BinString (if not, type it in) and click Next.

5. Select all the methods to be tested in the BinString class (do not select anything in the Object class). There should be 4 methods selected, then click Finish.

6. Add code to the test class to create and run tests of the two methods decimaltoBinary and binaryToDecimal. Include at least two test method calls for each one. Here is an example JUnit test method:

@Test

public final void testBinaryToDecimal1() {

int expected = 0;

assertEquals(expected, BinString.binaryToDecimal("000000000000"));

}

7. To run your test class, select your test class and choose Run as > JUnit Test from the Run drop-down menu in the toolbar. You can view the results of the test in the JUnit window. Red bar means the tests failed, green bar indicates that all tests pass.

The goal here is to write tests that will uncover any potential errors. Were you able to discover the error in BinString? Show your TA the corrected code and describe how you corrected the bug.

For more information on JUnit testing, you can refer to this Eclipse tutorial: Help -> Help Contents -> Java Development User Guide -> Getting Started -> Basic tutorial -> Writing and running JUnit tests.

Part 1 - Unit Testing Recursive Methods

Download the RecursiveMethods.java and RecursiveMethodsTest.java files and import them into your Lab6 project folder. Execute the test and they should fail because the RecursiveMethods class consists of method stubs.

Implement the recursive methods until all pass the provided unit tests. Once again show the green bar and completed RecursiveMethods.java file to your TA.

Attachment:- Assignment Files.rar

Reference no: EM132243502

Questions Cloud

Defining the audience that should receive the communication : Currently Hoosier Media utilizes traditional media vehicles for marketing. This includes print advertising to solicit new and renewal newspaper subscriptions.
Leadership traits and behaviours : Class materials on leadership topics such as: leadership traits and behaviours, contingency approaches to leadership, power and politics,
What is the primary purpose of project scope management : What is the primary purpose of Project Scope Management? Which of the following is a valid requirement classification? What is a work package?
What information privacy principals have been breached : Based on the video, your readings this week, please respond to the following questions: What information privacy principals have been breached?
Describe the basic concepts and techniques of unit testing : CMSC 256 Data Structures And Object Oriented Programming Assignment - JUnit in Eclipse and Recursion Lab, Virginia Commonwealth University, USA
Reflective essay on diversity : LA498 - LIBERAL ARTS CAPSTONE - Excelsior college - Demonstrate how you have met the ethics outcome through your past coursework or work experiences
How world events may have affected talent management : As you speculate how world events may have affected talent management, determine a method to refresh the talent management strategy of your organization.
Complains about having to share office with her coworkers : Lexie is a lackluster employee who rarely comes to the office and always complains about having to share an office with her coworkers.
How the personnel changes could impact quality : Imagine that you are the CEO of a large, metropolitan, multispecialty health care organization located in an urban city within the United States.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Calculate the total remaining health of each army

Pass in and set each army (an army is an array list of Warriors). Calculate the total remaining health of each army. Print out the attack strength of each warrior of each army

  What are the main differences between java programming

question 1 what are the major differences between java programming language and any other language? list and discuss

  What is an example of a javascript framework

What is an example of a JavaScript(r) framework? In the framework you have described, what is an example of an application that would work well on the site you are building for the class? What is the purpose of the application and how will it enha..

  Write a java program that inserts 25 random integers

Write a Java program that inserts 25 random integers ranging from 0 to 100 into an ArrayList in ascending order. The program should then output the numbers and display the sum and average of the numbers.

  Find information about scripting languages

Describe the primary features, strengths, and weaknesses of each language - Identify a task that would be an appropriate use of each language.

  Calculate the monthly compound interest rate using java

What is the formula to calculate the monthly compound interest rate using Java - Welcome this program will use a basic financial formula

  Create an application that uses a graphic interface

Create an application that uses a graphic interface to capture room assignment data for dormitory residents and writes that data to a random access output file.

  Implement a recursive search function in java

Implement a recursive search function in Java - What is the running time complexity of your function?

  The data file being used contains records

The data file being used contains records with an employee's name, the number of hours they worked, and their hourly pay rate. Write a program to read the records of information and output (to the Output window or a dialog box) the employee's name..

  Determine the classes that are required for the design

MN404- T1 2017 Fundamentals of Operating Systems and Java Programming Assessment. Determine the classes that are required for the design

  Write a java applet that views staff information

Write a Java applet that views, inserts, and updates staff information stored in a table Staff in an Oracle Database. The View button displays a record with a specified ID

  Simple java program that plays tic tac tow

Looking for a simple Java program that plays tic tac tow and using a 2D array and have A.I. Look at the attachment for the instructions.

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