To reduce time required for test runs application context is reused sometimes in different tests.
It is highly relevant for integration tests.
By "application context" here could be considered Spring-context.
It's suggested to introduce "reset" method to metrics to be able to start from scratch in a particular test case if it's needed.
Also it makes sense to add such method on MetricRegistry level (moreover, maybe it's enough - no need to add for each Metric type).
For example
MetricRegistry registry = new DefaultMetricRegistry();
Counter counter = registry.counter(withName("counter"));
counter.inc();
counter.inc();
counter.forEach(instance -> {
Long v = (Long)instance.valueOf(COUNT);
// Current value: 2
System.out.println("Current value: " + v);
});
counter.reset();
// or
registry.resetMetrics();
// Current value: 0
System.out.println("Current value: " + v);
To reduce time required for test runs application context is reused sometimes in different tests.
It is highly relevant for integration tests.
By "application context" here could be considered Spring-context.
It's suggested to introduce "reset" method to metrics to be able to start from scratch in a particular test case if it's needed.
Also it makes sense to add such method on MetricRegistry level (moreover, maybe it's enough - no need to add for each Metric type).
For example