Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Spring Boot, how to reset the metrics registry before each test?

I have tests and want to make assertions against micrometer metrics, but the tests run in random order so I want to reset or clear all the micrometer metrics before each test so my assertion are always correct.

like image 275
lfmunoz Avatar asked Aug 22 '19 20:08

lfmunoz


1 Answers

It depends on the Meter registry used. If you are using a SimpleMeterRegistry you could do:

registry.getMeters().forEach((meter) -> registry.remove(meter))
like image 107
checketts Avatar answered Oct 03 '22 12:10

checketts