HTW Berlin Medieninformatik HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 1: Informatik I
Winter Term 2022/23

Laboratory 7 : JUnit

Pre-lab

This week's lab work is intended give you practice testing and writing assertions with JUnit.

What to Bring to Lab

Please bring these exercises printed out or written out with you to lab. Please have your name on your page.

P1. Write down six test cases for a diary system that keeps track of Appointments on a specific Day. Give each test case a name like in the lecture.

P2. What assertions do you need in order to be able to automate the tests?

Post-Lab, AKA  What To Turn In

Your completed assignment, submitted in Moodle as a pdf, should include:

Lab assignments are due before your next lab at 22.00. They may, of course, be turned in earlier. You hand them in by preparing the report in PDF and submitting it to Moodle.


Assignment

Diary

  1. A diary is a system for keeping track of appointments on specific days and specific hours. We are going to work with a diary that only can take one appointment per hour, starting at 9 a.m. with the last appointment going from 5 p.m. to 6 p.m. You will be given an implementation that probably contains errors. Your job is to find the errors. You are only to develop tests and to find and describe errors, not to fix them.

    Install the diary project in the lab. Play around with the system for a few minutes. Create a method in DayTest to check that findSpace returns the value of 10 for a one-hour appointment, if a day already has a single one-hour appointment at 9 a.m. In essence, you need to use makeAppointment for the first appointment and findSpace for the second appointment. You will need to specify assertions for the results of both calls.
  2. Create a test to check that findSpace returns a value of -1, if an attempt is made to find an appointment in a day that is already full.
  3. Create a test class that has Appointment as its reference class. Record, using the record button control, separate test methods within it, that check that the description and duration fields of an Appointment object are initialized correctly following its creation.
  4. Create a negative test in the DayTest class. For example, try and set up a one-hour appointment, and then put in a two-hour appointment at the same time. What happens when you run the test? Include a screenshot in your report.
  5. Set up a fixture for an additional test case from your pre-lab. What did you have to do?
  6. Add further automated tests (positive and negative) to the DayTest class, until you are reasonably confident of the correct operation of the classes. If you discover any errors, be sure to record tests that guard against recurrence of these errors in later versions.
  7. (Only for the bored) Correct any errors that you find and run a regression text. Document what you have to change and how you ran the regression test!
  8. (For the bored) Expand the diary to accept appointments on the half-hour. Test.
  9. (For the exceedingly bored) Expand the diary to permit overlap of appointments. Test.

Writeup

Submit your writeup as your post-lab to the Moodle area.

 


Copyright Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. CC-BY-NC-SA - Copyright and Warranty

The exercises are adapted from Objects First with Java, A Practical Introduction Using BlueJ. David Barnes & Michael Kölling, 2016