编译命令:gcc-o autosell -fprofile-arcs -ftest-coverage autosell.c

  执行程序(./autosell)随便输入一些测试用例:

  测试结果:

  显示总体覆盖率:gcov autosell.c
  File'autosell.c'
  Linesexecuted:94.55% of 55
  Creating'autosell.c.gcov'

  显示函数覆盖信息:gcov-f autosell.c
  Function'process'
  Linesexecuted:90.00% of 20
  Function'pushbutton'
  Linesexecuted:100.00% of 9
  Function'getcoin'
  Linesexecuted:100.00% of 9
  Function'nochange'
  Linesexecuted:75.00% of 4
  Function'welcome'
  Linesexecuted:100.00% of 4
  Function'main'
  Linesexecuted:100.00% of 9
  File'autosell.c'
  Linesexecuted:94.55% of 55
  Creating'autosell.c.gcov'

  显示分支信息:gcov-b autosell.c
  File'autosell.c'
  Linesexecuted:94.55% of 55
  Branchesexecuted:100.00% of 28
  Takenat least once:92.86% of 28
  Callsexecuted:87.50% of 24
  Creating'autosell.c.gcov'

  具体的autosell.c.gcov信息自行查看

  参考资料:

  [1]软件测试实验指导教程/蔡建平, 清华大学出版社, 2009.11

  [2]软件测试学习:测试覆盖率工具EclEmma安装与使用:http://liangruijun.blog.51cto.com/3061169/803473

  [3]使用Eclemma进行覆盖测试:http://www.ibm.com/developerworks/cn/java/j-lo-eclemma/