Lab: White Box Testing
Steven Zeil
In this lab, we will look at white-box testing of a program that you should all be quite familiar with.
1 Setup
-
Review the program from the earlier “Working with ADTs” assignment in light of what you have learned this week about white-box testing.
-
Log into your account on one of our Linux servers. Create a convenient working directory,
cd
into it. Copy into that directory your code from that earlier assignment.If you did poorly in that assignment, you can return to the assignment’s submission page and get our solution. But if you got even partial credit for correct operation on that assignment, it may be more interesting to stick with your own code and see whether white-box testing might have helped.
-
Add to your working directory this makefile.
Be careful – some web browsers will try to rename that file to “
makefile.
” or “makefile.txt
” when you download it. The name should simply be “makefile
”. If your browser gives you something else, use the Linuxmv
command to rename the file, -
Delete any executable or object code (
.o
) files in the directory. (You can do this via the usual Linuxrm
command or by issuing the commandmake clean
).
2 Statement Coverage
-
Compile the program by giving the command
make
.Note that the
g++
compilation commands being issued include the special command flags for tracking white-box coverage.The makefile should generate an executable program named
mainProgram
. -
Execute the compiled program on any test data that you used for the assignment.
-
Generate the statement coverage report by giving the command
make report1
-
Look at the directory. You should see several
*.gcov
files. Some of these correspond to the.h
and.cpp
files of your program. Some may correspond to files from the C++std::
library.Examine the
*.gcov
files corresponding to the.cpp
files of your code using an editor or themore
orless
commands.Were any statements missed by your tests?
-
Get the instructors’ test data distributed with the assignment solution and run it through the program. Re-generate the statement coverage report and examine the
*.gcov
files again. Did the coverage improve?
3 Branch Coverage
-
Reset the coverage statistics by giving the command
make reset
-
Execute the compiled program on any test data that you used for the assignment.
-
Generate the branch coverage report by giving the command
make report2
-
Examine the
*.gcov
files corresponding to the.cpp
files of your code using an editor or themore
orless
commands.Were any branches missed by your tests?
-
Get the instructors’ test data distributed with the assignment solution and run it through the program. Re-generate the branch coverage report and examine the
*.gcov
files again. Did the coverage improve?