Function Repository Resource:

VerificationTestCoverage

Source Notebook

Count VerificationTest definitions for each function in a package

Contributed by: Jon McLoone

ResourceFunction["VerificationTestCoverage"][sourcecode,verificationtests]

counts how many verification tests involve each of the functions defined in sourcecode.

ResourceFunction["VerificationTestCoverage"][{source1,source2,..}, {verificationtests1,verificationtest2,}]

counts VerificationTest coverage for a collection of source files and test files.

Details

The test file can be either a plain text.wlt file or a Testing Notebook saved as a.nb file.
ResourceFunction["VerificationTestCoverage"] does not take into account contexts, either through Begin or BeginPackage or when explicitly given. For example a`f and b`f will both be treated as f in both the code and VerificiationTest files.

Examples

Basic Examples

For the following source code:

In[1]:=
source = Export["testsource.m", "
f[x_]:=g[x]+1;
g[x_]:=x^2
", "String"];

And the following test file:

In[2]:=
source = Export["testtests.m", "
VerificationTest[g[1],1];
VerificationTest[g[2],4];
", "String"];

We can see that there are two tests of the function g but none for the function f:

In[3]:=
ResourceFunction[
 "VerificationTestCoverage"]["testsource.m", "testtests.m"]
Out[3]=

Publisher

Jon McLoone

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.3 – 09 August 2023
  • 1.0.2 – 06 January 2023
  • 1.0.1 – 18 March 2022
  • 1.0.0 – 18 January 2022

Related Resources

License Information