Prolog Unit Tests
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Prolog Unit Tests
        • Introduction
        • A Unit Test box
        • Using separate test files
        • Running the test-suite
        • Tests and production systems
        • Controlling the test suite
        • Auto-generating tests
        • Coverage analysis
          • show_coverage/1
        • Portability of the test-suite
        • Motivation of choices

8 Coverage analysis

An important aspect of tests is to know which parts of program is used (covered) by the tests. An experimental analysis is provided by the library library(test_cover).

show_coverage(:Goal)
Run Goal and write a report on which percentage of the clauses in each file are used by the program and which percentage of the clauses always fail.

We illustrate this here using CHAT, a natural language question and answer application by David H.D. Warren and Fernando C.N. Pereira.

1 ?- show_coverage(test_chat).
Chat Natural Language Question Answering Test
...

==================================================================
                         Coverage by File
==================================================================
File                                        Clauses    %Cov %Fail
==================================================================
/staff/jan/lib/prolog/chat/xgrun.pl                5   100.0   0.0
/staff/jan/lib/prolog/chat/newg.pl               186    89.2  18.3
/staff/jan/lib/prolog/chat/clotab.pl              28    89.3   0.0
/staff/jan/lib/prolog/chat/newdic.pl             275    35.6   0.0
/staff/jan/lib/prolog/chat/slots.pl              128    74.2   1.6
/staff/jan/lib/prolog/chat/scopes.pl             132    70.5   3.0
/staff/jan/lib/prolog/chat/templa.pl              67    55.2   1.5
/staff/jan/lib/prolog/chat/qplan.pl              106    75.5   0.9
/staff/jan/lib/prolog/chat/talkr.pl               60    20.0   1.7
/staff/jan/lib/prolog/chat/ndtabl.pl              42    59.5   0.0
/staff/jan/lib/prolog/chat/aggreg.pl              47    48.9   2.1
/staff/jan/lib/prolog/chat/world0.pl             131    71.8   1.5
/staff/jan/lib/prolog/chat/rivers.pl              41   100.0   0.0
/staff/jan/lib/prolog/chat/cities.pl              76    43.4   0.0
/staff/jan/lib/prolog/chat/countr.pl             156   100.0   0.0
/staff/jan/lib/prolog/chat/contai.pl             334   100.0   0.0
/staff/jan/lib/prolog/chat/border.pl             857    98.6   0.0
/staff/jan/lib/prolog/chat/chattop.pl            139    43.9   0.7
==================================================================

Using ?- show_coverage(run_tests)., this library currently only shows some rough quality measure for test-suite. Later versions should provide a report to the developer identifying which clauses are covered, not covered and always failed.