Testing, Debugging, and Verification | TDA566/DIT082, LP2, HT2013 | ||
Lab 1 - Software Testing | |||
1. Black-box Testing Your task is to derive test cases for a number of methods using their specifications. Analyse the specifications in order to divide the set of possible inputs into different situations. Then write a set of test cases for each method, which covers the different cases well. For each test case, give a comment which describes what situation it tests. In a report file, you must explain and motivate why you divided the test cases in the way you did. You must show how you defined the input space, and how you partitioned it. The assignment is about a class called WorkSchedule. The purpose of the class is to manage the schedule for the employees of a company. The time is divided in units of 1 hour and the hours are simply identified by integers (Note that this is an unrealistic simplification). For each hour, the schedule stores the number employees which is needed at that time. It could for instance be that during week-days the need is that 5 employees work at the same time, but less during nights and weekend. For each hour the schedule also stores the names of the employees who have been assigned to work at that hour.
The methods of the class are: public WorkSchedule(int size) { ... } public Hour readSchedule(int time) { ... } public void setRequiredNumber(int nemployee, int starttime, int endtime) { ... } public boolean addWorkingPeriod(String employee, int starttime, int endtime) { ... } public String[] workingEmployees(int starttime, int endtime) { ... } public int nextIncomplete(int currenttime) { ... }
The constructor (WorkSchedule) and the method readSchedule are trusted to be correct and do not need to be tested. Note that readSchedule can be used to examine the state of a class instance.
A compiled implementation of the class can be found in the following Java archive: WorkSchedule.jar You are supposed to run your test cases on the methods in the .jar-file. Note that some methods may be correctly implemented, and some may contain bugs.
a. specification for seqRequiredNumber requires: starttime >= 0, endtime < size, starttime <= endtime, nemployee >= 0 ensures: For i between starttime and endtime, the requiredNumber of hour i equals nemployee. For all other i the schedule is unchanged.
b. specification for addWorkingPeriod requires: employee is a non-null string ensures: if starttime < 0 or endtime >= size or starttime > endtime then returns false and the schedule is unchanged otherwise if for any hour in the interval starttime to endtime the length of workingEmployees is equal to requiredNumber then returns false and the schedule is unchanged otherwise if for any hour in the interval starttime to endtime there is a string in workingEmployees which equal employee then returns false and the schedule is unchanged otherwise returns true, for i between starttime and endtime, workingEmployees contain a string equal to employee and the rest of the schedule is unchanged
c. specification for workingEmployees requires: starttime >= 0 and endtime < size ensures: if starttime <= endtime then returns an array with distinct strings a string appears in the return array if and only if it appears the workingEmployees of at least one hour in the interval starttime to endtime otherwise returns an empty array and in either case the schedule is unchanged
d. specification for nextIncomplete requires: currenttime >= 0 and currenttime < size ensures: if there is an hour in the interval currenttime to size - 1 such that the length of workingEmplyees is less that requiredNumber then returns the time of the hour closest to currenttime such that the length of workingEmplyees is less that requiredNumber otherwise returns -1 in either case the schedule is unchanged 2. White-box Testing For the assignments in part 2 you will be using the source code of the methods. For each method you should first derive a suite of test cases which together have full statement coverage of the source code. Then you should write additional test cases (if any are needed) which together with the ones already there have full branch coverage of the code. The test cases should be executable with JUnit just like in part 1 of the lab. If any of the test cases for a method fails, try to find the bug and correct the source code. Keep in mind that you may need a method, A, to set up the test of another method, B. If the method A has a bug it can be very tricky to test method B. Wherever possible you can first fix the bug in a method and then do the tests that use it in the setup (or test oracle). Also keep in mind that a bug in the implementation may imply that full statement or branch coverage is not possible. This it in itself an indication of the bug's existence. In such case, it's enough if you have full coverage after fixing the bug. The assignment is about the class Set.
Set represents sets of integers.
The elements of a set are stored in an ArrayList.
They are sorted and without duplicates to speed up some operations.
Two methods might need an explanation: Note that you can use toArray to easily examine the state of a class instance.
a.
b.
c.
d.
e.
| |||
Home | Course | Schedule | Exam | Exercises | Labs | Evaluation | Tools | Links | Moa Johansson, Nov 5, 2012 |