1Metrics::Any::Adapter::UTseesrt(C3o)ntributed Perl DocumMeenttraitciso:n:Any::Adapter::Test(3)
2
3
4
6 "Metrics::Any::Adapter::Test" - a metrics reporting adapter for unit
7 testing
8
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
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 the count and total
31 duration.
32
33 For predictable output of timer metrics in unit tests, a unit test may
34 wish to use the "override_timer_duration" method.
35
37 metrics
38 $result = Metrics::Any::Adapter::Test->metrics
39
40 This class method returns a string describing all of the stored metric
41 values. Each is reported on a line formatted as
42
43 name = value
44
45 Each line, including the final one, is terminated by a linefeed. The
46 metrics are sorted alphabetically. Any multi-part metric names will be
47 joined with underscores ("_").
48
49 Metrics that have additional labels are formatted with additional label
50 names and label values in declared order after the name and before the
51 "=" symbol:
52
53 name l1:v1 l2:v2 = value
54
55 clear
56 Metrics::Any::Adapter::Test->clear
57
58 This class method removes all of the stored values of reported metrics.
59
60 override_timer_duration
61 Metrics::Any::Adapter::Test->override_timer_duration( $duration )
62
63 This class method sets a duration value, that any subsequent call to
64 "inc_timer" will use instead of the value the caller actually passed
65 in. This will ensure reliably predictable output in unit tests.
66
67 Any value set here will be cleared by "clear".
68
70 Paul Evans <leonerd@leonerd.org.uk>
71
72
73
74perl v5.32.0 2020-07-28 Metrics::Any::Adapter::Test(3)