0% found this document useful (0 votes)
17 views15 pages

Spring22-Exercise3-UnitTesting

The document outlines an exercise session focused on unit testing for a scheduling system, detailing its high-level features such as booking meetings and checking availability. It emphasizes the importance of developing a test plan and running exploratory tests to identify potential faults in the code, including issues with date handling and error checking. Additionally, it encourages participants to expose faults and consider various scenarios that could lead to errors in the system.

Uploaded by

chistafair.it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views15 pages

Spring22-Exercise3-UnitTesting

The document outlines an exercise session focused on unit testing for a scheduling system, detailing its high-level features such as booking meetings and checking availability. It emphasizes the importance of developing a test plan and running exploratory tests to identify potential faults in the code, including issues with date handling and error checking. Additionally, it encourages participants to expose faults and consider various scenarios that could lead to errors in the system.

Uploaded by

chistafair.it
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Exercise Session 3:

Unit Testing
Gregory Gay
DIT635 - February 11, 2022
Enter… The Planning System
Code: https://bit.ly/3B39YYI
Activity: https://bit.ly/32XM308

• 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: https://bit.ly/3B39YYI
The Planning System Activity: https://bit.ly/32XM308

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: https://bit.ly/3B39YYI
Develop a Test Plan Activity: https://bit.ly/32XM308

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: https://bit.ly/3B39YYI
Activity: https://bit.ly/32XM308

• 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: https://bit.ly/3B39YYI
Develop Unit Tests Activity: https://bit.ly/32XM308

• 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 occupied.get(month).get(day).get(index);
}

public void removeMeeting(int month, int day, int index){


occupied.get(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
occupied.add(new ArrayList<ArrayList<Meeting>>());
for(int j=0;j<32;j++){
// Initialize days
occupied.get(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.
occupied.get(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: https://bit.ly/3B39YYI
Activity: https://bit.ly/32XM308

What Other Faults Can You Find?

13
Current Status Code: https://bit.ly/3B39YYI
Activity: https://bit.ly/32XM308

I and the TAs are available to answer questions.


• Afonso Fontes
• Sandra Eisenberg
• Chaneli Silva

14

You might also like