1Metrics::Any::Adapter::UTseesrt(C3o)ntributed Perl DocumMeenttraitciso:n:Any::Adapter::Test(3)
2
3
4

NAME

6       "Metrics::Any::Adapter::Test" - a metrics reporting adapter for unit
7       testing
8

SYNOPSIS

10          use Test::More;
11          use Metrics::Any::Adapter 'Test';
12
13          {
14             Metrics::Any::Adapter::Test->clear;
15
16             # perform some work in the code under test
17
18             is( Metrics::Any::Adapter::Test->metrics,
19                "an_expected_metric = 1\n",
20                'Metrics were reported while doing something'
21             );
22          }
23

DESCRIPTION

25       This Metrics::Any adapter type stores reported metrics locally,
26       allowing access to them by the "metrics" method. This is useful to use
27       in a unit test to check that the code under test reports the correct
28       metrics.
29
30       This adapter supports timer metrics by storing as distributions. By
31       default, distributions store only a summary, giving the count and total
32       duration. If required, the full values can be stored by setting
33       "use_full_distributions".
34
35       For predictable output of timer metrics in unit tests, a unit test may
36       wish to use the "override_timer_duration" method.
37
38       This adapter type supports batch mode reporting. Callbacks are invoked
39       at the beginning of the "metrics" method.
40

METHODS

42   metrics
43          $result = Metrics::Any::Adapter::Test->metrics
44
45       This class method returns a string describing all of the stored metric
46       values.  Each is reported on a line formatted as
47
48          name = value
49
50       Each line, including the final one, is terminated by a linefeed. The
51       metrics are sorted alphabetically. Any multi-part metric names will be
52       joined with underscores ("_").
53
54       Metrics that have additional labels are formatted with additional label
55       names and label values in declared order after the name and before the
56       "=" symbol:
57
58          name l1:v1 l2:v2 = value
59
60   use_full_distributions
61          Metrics::Any::Adapter::Test->use_full_distributions;  # enables the option
62
63          Metrics::Any::Adapter::Test->use_full_distributions( $enable );
64
65       Since version 0.08.
66
67       If enabled, this option stores the full value of every reported
68       observation into distributions, rathr than just the count-and-total
69       summary.
70
71       Full value distributions will be formatted as a sequence of lines
72       containing the count of observations at that particular value, in
73       square brackets, followed by the summary count.
74
75          name[v1] = c1
76          name[v2] = c2
77          ...
78          name_count = c
79
80       In order not to be too sensitive to numerical rounding errors, values
81       are stored to only 3 decimal places.
82
83   clear
84          Metrics::Any::Adapter::Test->clear
85
86       This class method removes all of the stored values of reported metrics.
87
88   override_timer_duration
89          Metrics::Any::Adapter::Test->override_timer_duration( $duration )
90
91       This class method sets a duration value, that any subsequent call to
92       "inc_timer" will use instead of the value the caller actually passed
93       in. This will ensure reliably predictable output in unit tests.
94
95       Any value set here will be cleared by "clear".
96

AUTHOR

98       Paul Evans <leonerd@leonerd.org.uk>
99
100
101
102perl v5.36.0                      2023-01-20    Metrics::Any::Adapter::Test(3)
Impressum