Exercise 6
info
This is an in-class exercise. An exercise page like this one will contain a brief description but is intended to be supplemented by discussion during our meeting time. Complete the exercise to the best of your ability in the time given. Feel free to talk with other students as you work, and do not be afraid to ask questions. Aim to complete as much as possible during our meeting and continue to work at home to finish, but you need not hand it in.
#
Learning ObjectivesObjectives
This exercise should help you practice with:
- Logic-based testing
- Logic-based coverage criteria
#
Quick QuestionIt was mentioned in class that Clause Coverage does not subsume Predicate Coverage. Give an actual example that shows this.
#
Task 1: Logic-based testing applied to source codeConsider the following code where turnHeaterOn
decides whether a thermostat must be turned on or not and for how long:
Conduct logic-based testing on the first if
statement within the turnHeaterOn
to achieve:
- Predicate coverage (i.e., branch coverage)
- Clause coverage (i.e., condition coverage)
- Correlative Active Clause Coverage (CACC)
- Write actual test cases for CACC
tip
dTemp
is an example of an internal variable. An internal variable is one that its value is not directly fed into the program; Rather, we need to set the values of period
and day
such that we get the desirable value for dTemp
.
tip
To make your work easier when writing test requirements for each criterion, rewrite the predicate in the if
statement in short form; that is for each cluase use a short notation e.g., (curTemp < dTemp - thresholdDiff)
is one cluase and you can call it A
. Similarly, use short notations for the other cluases in the predicate.
#
Task 2: Logic-based testing applied to specificationsConsider the following method:
- Formulate the pre-condition in the Javadoc as a logical predicate comprised of a number clauses.
- List test requirements (TRs) for CACC.
- Write actual test cases to satisfy all the listed TRs for CACC in step 1.