How to Set Up Erlang Common Test for Code Coverage

Common Test code coverage and usage is documented here and here, but:

  • there are no examples given
  • documentation fails to state what the minimum required configuration is to turn on code coverage
  • the implementation has no sane defaults and by default code coverage is disabled

So, here’s the minimum sane default:

  • create a cover.spec file in your application directory with the following contents
    {incl_app, my_app, details}.
    {excl_mods, my_app, [my_app_SUITE]}.

    where my_app and my_app_SUITE are names of your application and the test suite(s) you have
  • when running using ct_run, make sure to
    • either specify -cover cover.spec option; OR
    • add this line to your main CT spec file
      {cover, "cover.spec"}.

That’s it! Next time you run CT you should have a nice code coverage report generated with it.

Oh, also, it’s probably worth mentioning that I couldn’t get erlang.mk to run ct_run with the -spec option, so I manually added it in the CT_RUN command.

Advertisements