1Test::Metrics::Any(3) User Contributed Perl DocumentationTest::Metrics::Any(3)
2
3
4

NAME

6       "Test::Metrics::Any" - assert that code produces metrics via
7       Metrics::Any
8

SYNOPSIS

10          use Test::More;
11          use Test::Metrics::Any;
12
13          use Module::Under::Test;
14
15          is_metrics_from(
16             sub { Module::Under::Test::do_a_thing for 1 .. 5 },
17             {
18                things_done => 5,
19                time_taken => Test::Metrics::Any::positive,
20             },
21             'do_a_thing reported some metrics'
22          );
23
24          done_testing;
25

DESCRIPTION

27       This test module helps write unit tests which assert that the code
28       under test reports metrics via Metrics::Any.
29
30       Loading this module automatically sets the Metrics::Any::Adapter type
31       to "Test".
32

FUNCTIONS

34   is_metrics
35          is_metrics( \%metrics, $name )
36
37       Asserts that the current value of every metric named in the given hash
38       reference is set to the value provided. Values can either be given as
39       exact numbers, or by one of the match functions mentioned in
40       "PREDICATES".
41
42       Key names in the given hash should match the name format used by
43       Metrics::Any::Adapter::Test. Name components are joined by underscores,
44       and any label tags are appended with spaces, as "name:value".
45
46          {
47             "a_basic_metric"               => 123,
48             "a_labelled_metric label:here" => 456,
49          }
50
51       This function only checks the values of metrics actually mentioned in
52       the hash given as its argument. It is not a failure for more metrics to
53       have been reported by the code under test than are mentioned in the
54       hash. This helps to ensure that new metrics added in code do not break
55       existing tests that weren't set up to expect them.
56
57   is_metrics_from
58          is_metrics_from( $code, \%metrics, $name )
59
60       Asserts the value of metrics reported by running the given piece of
61       code.
62
63       The metrics in the test adapter are cleared, then the code is invoked,
64       then any metrics are checked in the same manner as "is_metrics".
65

PREDICATES

67       As an alternative to expecting exact values for metrics, the following
68       test functions can be provided instead to assert that the metric is
69       behaving sensibly without needing to be an exact value. This could be
70       useful for example when the exact number of bytes or timing measures
71       can vary between test runs or platforms.
72
73       These predicates are not exported but must be invoked fully-qualified.
74
75   positive
76          metric => Test::Metrics::Any::positive
77
78       Asserts that the number is greater than zero. It must not be zero.
79
80   at_least
81          metric => Test::Metrics::Any::at_least( $n )
82
83       Asserts that the number at least that given - it can be equal or
84       greater.
85
86   greater_than
87          metric => Test::Metrics::Any::greater_than( $n )
88
89       Asserts that the number is greater than that given - it must not be
90       equal.
91

AUTHOR

93       Paul Evans <leonerd@leonerd.org.uk>
94
95
96
97perl v5.32.0                      2020-07-28             Test::Metrics::Any(3)
Impressum