CMSC204 JUnit Test Classes Solved

30.00 $ 15.00 $

Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment


Rate this product

You will be creating a JUnit Test Class for, that has been provided for you.  Upload and to the repository in GitHub you created in Lab 1 in a directory named JUnit_Lab.

Add the following two methods to the Gradebook class.  Do not modify the other methods of Gradebook.

  1. Add a getScoreSize() method to the Gradebook class which returns scoresSize;
  2. Add a toString() method to the Gradebook class that returns a string with each score in scores separated by a space.

Create the Test Class GradebookTester.

  1. Select the setUp and tearDown method.
  2. Select all of the methods of Gradebook, except for the constructor to create tests for.
  3. In the setUp method of GradebookTester, create at least two objects of Gradebook of size 5. Call the addScore method for each of the Gradebook classes at least twice (but no more than 5 times).
  4. In the teardown method of GradebookTester, set the two objects of Gradebook to null;
  5. Create test for the methods of Gradebook:
    1. addScore
      1. Use the toString method to compare the contents of what is in the scores array vs. what is expected to be in the scores array

assertTrue( . . .)

  1. Compare the scoreSize to the expected number of scores entered.

assertEquals(. . .)

  1. sum
    1. Compare what is returned by sum() to the expected sum of the scores entered.
  2. minimum
    1. Compare what is returned by minimum() to the expected minimum of the scores entered.
  3. finalScore
    1. Compare what is returned by finalScore() to the expected finalscore of the scores entered.

The finalScore is the sum of the scores, with the lowest score dropped if there are at least two scores, or 0 if there are no scores.



Add a private member of GradeBookTest:

GradeBook g1;


In setup:

g1 = new GradeBook(5);




In teardown:

g1 = null;


in testSum():

assertEquals(125, g1.sum(), .0001);


in testMinimum():

assertEquals(50, g1.minimum(), .001);


in addScoreTest();

assertTrue(g1.toString().equals(“50.0 75.0 ”);