ruststream 0.7.5

Async messaging framework for Rust: broker-agnostic traits, router, codecs, and a conformance harness for broker authors.
Documentation
---
title: assert_called_once (published assertions)
sidebar_label: assert_called_once
sidebar_position: 1
description: "assert_called_once checks that exactly one message was published to the destination."
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# assert_called_once

[`assert_called_once`](api:ruststream::testing::PublishedAssertions::assert_called_once) checks that exactly one message was published to the destination.

The assertion counts the messages in the record, [`published::<T>(name)`](../records/published.md), not the handler calls that produced them.
It panics with the count it found when the record holds none or more than one.
It returns the record, so `with`, `with_raw` and `with_header` chain after it.
[`assert_called(n)`](./assert-called.md) checks any other count, and [`assert_not_called`](./assert-not-called.md) checks that nothing was published.

## Example

<Tabs groupId="api">
<TabItem value="macros" label="Macros">

```rust reference="examples/testing_published.rs#assert-called-once"
```

</TabItem>
<TabItem value="manual" label="Manual">

```rust reference="examples/manual/testing_published.rs#assert-called-once"
```

</TabItem>
</Tabs>