Library Moduleswift-metrics 2.6.1MetricsTestKit
MetricsTestKit
A set of tools for testing Metrics emitting libraries.
import MetricsTestKit
Module information
- Declarations
- 88
- Symbols
- 96
Overview
This module offers a TestMetrics
type which can be used to bootstrap the metrics system and then assert metric values on it.
Example
import XCTest
import Metrics
import MetricsTestKit
final class ExampleTests: XCTestCase {
var metrics: TestMetrics! = TestMetrics()
override func setUp() {
MetricsSystem.bootstrapInternal(self.metrics)
}
override func tearDown() async throws {
self.metrics = nil
MetricsSystem.bootstrapInternal(NOOPMetricsHandler.instance)
}
func test_example() async throws {
// Create a metric using the bootstrapped test metrics backend:
Recorder(label: "example").record(100)
// extract the `TestRecorder` out of the
let recorder = try self.metrics.expectRecorder("example")
recorder.lastValue?.shouldEqual(6)
}
}