Exercise

CLICK HERE TO DOWNLOAD THIS TUTORIAL INSTANTLY $24 Only

1. Create a test class for the Comment class in the online-shop-junit project.

2. What methods are created automatically when a new test class is created?

3. Create a test to check that add Comment returns false when a comment from the same author already exists.

4. Create a test that performs negative testing on the boundaries of the rating range. That is, test the values 0 and 6 as a rating (the values just outside the legal range). We expect these to return fa1se, so assert false in the result dialog. You will notice that one of these actually (incorrectly) returns true. This is the bug we uncovered earlier in manual testing. Make sure that you assert false anyway. The assertion states the expected result, not the actual result.

5. Create a test class that has Comment as its reference class.
Create a test that checks whether the author and rating details are stored correctly after creation.
Record separate tests that check whether the u pv0te and d own v 0 t e methods work as expected.

6. Create tests for Sa1es Item that test whether the findMostHelpful Comment method works as expected. Note that this method returns a Comment object. During your testing, you can use the Get button in the method result dialog to get the result object onto the object bench, which then allows you to make further method calls and add assertions for this object. This allows you to identify the comment object returned (e.g., by checking its author). You can also assert that the result is null or not null, depending on what you expect.

7. Add further automated tests to your project until you reach a point where you are reasonably confident of the correct operation of the classes. Use both positive and negative tests. If you discover any errors, .be sure to record tests that guard against recurrence of these errors in later versions.