1. Add the compilation and link parameters:-fprofile-arcs-ftest-coverage. Take eclipse as an example. Add the preceding parameters to a C ++ project:
Project-> properties-> C/C ++ build-> Settings-> gcc C ++ compiler-> command: Enter g ++-fprofile-arcs-ftest-coverage
Project-> properties-> C/C ++ build-> Settings-> gcc C ++ linker-> command: Enter g ++-fprofile-arcs-ftest-coverage
2. Clear and build the entire project. 3. Run an executable file or test. 4. Generate a coverage report for a file. For example: sudo gcov ../src/clist. cpp-o ../debug/src/Because gcov needs to read and create files, we recommend that you use sudo for execution... /Src/clist. cpp indicates the source file to be analyzed. The-O parameter indicates that after the. o file is executed, clist. cpp. gcov is generated in the current directory. This is the coverage report of the file. 5. view the coverage report and view the clist. cpp. gcov file. The Rows marked with "####" indicate the rows that have not been overwritten. Supplement: CodeThe coverage rate check works with unit tests to improve the code quality test!