Learning Objectives: practice at designing unit tests to meet coverage
criteria; better understanding of MCDC coverage.
Notes:
- Be sure to check the supplemental material at the bottom of this
assignment for videos on various aspects of coverage. Optional, but might be
helpful.
- We teach cunit because it is more commonly supported on smaller embedded
systems. For this homework you can use GUnit or other reasonable notation if
you prefer. However, the course staff does NOT provide support for GUnit, so
use at your own risk on the project.
16-1. Two important concepts in black box testing are equivalence
classes and boundary values. For this question consider an absolute value
function:
int16_t abs16(int16_t i) { return (i < 0 ? -i : i); }
- 16-1a. Give a concise definition of an equivalence class (paraphrase; cite
your source)
- 16-1b. For purposes of black box testing, there are 4 equivalence classes
for the above procedure abs16(). List the four classes using a concise English
description.
- 16-1c. List the boundary values for each equivalence class identified in
the previous question.
- 16-1d. Using "cunit" notation, list a set of tests for abs16 that
checks for correct calculation results for all boundary values and for each
equivalence class that has more than one value, also includes an arbitrarily
picked representative non-boundary value. This should total 8 tests. (You do
not have to compile & run; we'll use cunit in the project later.)
16-2. Consider testing the following code:
int16_t baz(int16_t a, int16_t b)
{ int16_t res = 0;
if( ((b < 6) && (a < 27)) || (b > 87) || (a == 52) )
{ res = b;
} else
{ res = a;
}
return(res);
}
- 16-2a. Make a truth table to show the combinations for the four conditions
that need to be tested to attain 100% MCDC coverage. (Columns should be
condition clauses; rows should each be a required set of test values.) Note
that this is NOT all combinations for true/false for each condition, but rather
just the minimum necessary set for 100% MCDC coverage. If you want to show all
rows and then indicate the rows needed for MCDC testing that's OK.
- 16-2b. Using "cunit" notation list sufficient test cases to
obtain 100% MCDC coverage. (Note that you do NOT need to exercise both boundary
and non-boundary values. Just identify test cases for MCDC coverage.
16-3.Consider testing the following code:
int16_t bar(int16_t a, int16_t b)
{ int16_t res = 0;
if((a > 3) && (b < 112))
{ if (a == 42)
{ res = b;
} else
{ res = a;
}
} else
{ res = a-b;
if (a == 2 && b == 2)
{ res = a+b;
}
}
return(res);
}
- 16-3a. Make a truth table to show the combinations for the conditions that
need to be tested to attain 100% MCDC coverage. (Columns should be condition
clauses; rows should each be a required set of test values.) Note that this is
NOT all combinations for true/false for each condition, but rather just the
minimum necessary set for 100% MCDC coverage.If you want to show all rows and
then indicate the rows needed for MCDC testing that's OK.
- 16-3b. Using "cunit" notation list sufficient test cases to
obtain 100% MCDC coverage. (Note that you do NOT need to exercise both boundary
and non-boundary values. Just identify test cases for MCDC coverage.
Rubric:
- 16-1a: definition (<25 words)
- 16-1b. four classes (4 x <10 words)
- 16-1c. boundary values (four sets of boundary values)
- 16-1d. Eight tests in cunit or gunit format
- 16-2a. Truth table, 16 or fewer rows
- 16-2b. Fewer than 16 cunit/gunit tests
- 16-3a. Truth table for testing
- 16-3b. cunit/gunit tests
Supplemental Material: