Identifying Unused Code

This tutorial demonstrates using Coverage Validator to identify unused code in an application. The example application has some code in it that is deliberately unused so that we can demonstrate how to identify unused code.

  • Launch the sample application. Click on the launch icon on the toolbar. Alternatively, to relaunch the most recently launched application, click the launch icon with a green recycle arrow around it
    Coverage Validator relaunch toolbar
  • If the launch icon is selected, the Launch application dialog is displayed.
    Coverage Validator launch native application dialog

    • Select the sample application nativeExample.exe using the Browse… button, or select a previously executed application from the list at the bottom of the dialog.
    • Click the Launch button to launch the application.
    • The nativeExample.exe application is started.
  • If the relaunch icon is selected the most recently started application is started (for this tutorial we will assume this is nativeExample.exe).
  • Exercise as much of the application as possible. For this tutorial, the following actions should be performed:
    • Help menu, About Coverage Validator Tester….
    • Test menu, Test 1.
    • Test menu, Test 2.
    • File menu, Exit.
  • At the end of the test, one of the source code files has had no lines visited. This file is TestMemoryDialog.cpp.
    Coverage Validator unused code
  • Further examination of this file shows that it contains the class CTestMemoryDialog. Searching the source code for the application shows that this class is not used anywhere. This indicates this class is most likely surplus to requirements and can be removed from the build.

Conclusion

In this tutorial, you have learned how to identify potentially unused code in your software.

Fully functional, free for 30 days