Exercise Session 3:
Unit Testing
Gregory Gay
DIT635 - February 11, 2022
Enter… The Planning System
Code: [Link]
Activity: [Link]
• Everybody likes meetings.
• Not true - but we need to book them.
• We don’t want to double-book
rooms or employees for meetings.
• System to manage schedules and
meetings.
2
Code: [Link]
The Planning System Activity: [Link]
Offers the following high-level features:
1. Booking a meeting
2. Booking vacation time
3. Checking availability for a room
4. Checking availability for a person
5. Printing the agenda for a room
6. Printing the agenda for a person
3
Code: [Link]
Develop a Test Plan Activity: [Link]
In groups, come up with a test plan for this system.
• Given the features and the code documentation,
plan unit tests to ensure that these features can be
performed without error.
4
Food for Thought Code: [Link]
Activity: [Link]
• Try running the code!
• Perform exploratory testing to test it at the system level.
• Think about normal and erroneous inputs/actions.
• How many things can go wrong?
• You will probably be able to add a normal meeting, but
can you add a meeting for February 35th?
• Try it out - you have the code.
5
Code: [Link]
Develop Unit Tests Activity: [Link]
• If a test is supposed to cause an exception to be
thrown, make sure you check for that exception.
• Make sure that expected output is detailed enough
to ensure that - if something is supposed to fail -
that it fails for the correct reasons.
• Use proper assertions.
6
Can you expose the faults?
7
Can you expose the faults?
1: getMeeting and removeMeeting perform no error
checking on dates.
public Meeting getMeeting(int month, int day, int index){
return [Link](month).get(day).get(index);
}
public void removeMeeting(int month, int day, int index){
[Link](month).get(day).remove(index);
}
8
Can you expose the faults?
2: Calendar has a 13th month.
public Calendar(){
occupied = new ArrayList<ArrayList<ArrayList<Meeting>>>();
for(int i=0;i<=13;i++){
// Initialize month
[Link](new ArrayList<ArrayList<Meeting>>());
for(int j=0;j<32;j++){
// Initialize days
[Link](i).add(new ArrayList<Meeting>());
}
}
}
9
Can you expose the faults?
3: November has 30 days.
Oh - and we just added a meeting to a day with a date that
does not match that date.
[Link](11).get(30).add(new Meeting(11,31,"Day does not
exist"));
10
Can you expose the faults?
4: Used a >= in checking for illegal times. December
no longer exists.
if(mMonth < 1 || mMonth >= 12){
throw new TimeConflictException("Month does not
exist.");
}
11
Can you expose the faults?
5: We should be able to start and end a meeting in the
same hour.
if(mStart >= mEnd){
throw new TimeConflictException("Meeting starts before it
ends.");
}
12
Code: [Link]
Activity: [Link]
What Other Faults Can You Find?
13
Current Status Code: [Link]
Activity: [Link]
I and the TAs are available to answer questions.
• Afonso Fontes
• Sandra Eisenberg
• Chaneli Silva
14