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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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