FakeAnalyticsProvider

A vendor that records instead of sending, for tests in apps that use Herald.

It implements all five capabilities, so you can register it as a real provider and the test then runs through the composition root you actually ship — factory chain, dispatcher and all:

val analytics = FakeAnalyticsProvider()
val herald = Herald {
provider(name = "test", events = analytics, properties = analytics)
}

viewModel.onPayTapped()

analytics.assertTracked("checkout_pay_tapped") { param("plan", "pro") }
analytics.assertNothingElseTracked()

For a class that only tracks events a lambda is smaller — EventTrackerService { recorded += it } needs no dependency. Reach for this when the test spans more than one capability, cares about ordering between them, or runs through a real Herald.

Safe to call from several coroutines at once.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Just the events, in order.

Link copied to clipboard

Just the properties, in order.

Link copied to clipboard

Everything received, oldest first.

Functions

Link copied to clipboard

Asserts that the user was identified as userId at some point. Unlike assertPropertySet this is historical, not current: an identify followed by reset still passes. Use records to assert on the order.

Link copied to clipboard

Asserts that every event tracked has already been named by an earlier assertion.

Link copied to clipboard

Asserts that no event was tracked at all.

Link copied to clipboard

Asserts that no event with name was tracked.

Link copied to clipboard

Asserts that name is currently value: the last value it was set to, since a property is state and that is what a vendor holds. Earlier values do not count, so a property set to the right value and then overwritten fails, and the failure lists the sequence.

fun assertPropertySet(name: String, value: Boolean)
fun assertPropertySet(name: String, value: Double)
fun assertPropertySet(name: String, value: Float)
fun assertPropertySet(name: String, value: Int)
fun assertPropertySet(name: String, value: Long)
fun assertPropertySet(name: String, value: String)
Link copied to clipboard
fun assertTracked(name: String, assertions: TrackedEventAssert.() -> Unit = {})

Asserts that exactly one event with name was tracked, and applies assertions to it.

Link copied to clipboard
fun assertTrackedTimes(name: String, times: Int)

Asserts that name was tracked exactly times times.

Link copied to clipboard
fun clear()

Forgets everything, including which records have already been asserted on.

Link copied to clipboard
open suspend override fun flush()
Link copied to clipboard
open suspend override fun identify(identity: Identity)
Link copied to clipboard
open suspend override fun reset()
Link copied to clipboard
open suspend override fun set(property: Property)
Link copied to clipboard
open suspend override fun setEnabled(enabled: Boolean)
Link copied to clipboard
open suspend override fun start()
Link copied to clipboard
open suspend override fun track(event: Event)