Event and Event Bus Properties in Test Context
Deliver Test Event Messages
Test Retried Event Messages
Encrypting Platform Event Messages at Rest in the Event Bus
Previous Versions
Add Apex tests to test platform event subscribers. Before you can package or deploy Apex code, including triggers, to production, it must have tests and sufficient code coverage. Add Apex tests to provide code coverage for your triggers.
Event and Event Bus Properties in Test Context
In test context, event messages and the event bus have different properties. State information of events and subscribers is reset and isn’t persisted.
Deliver test event messages after the Test.stopTest() statement. Alternatively, deliver test event messages at any time with the Test.getEventBus().deliver() method. Fail test event messages with the Test.getEventBus().fail() method.
An Apex trigger can retry processing of an event message by throwing EventBus.RetryableException. In API version 43.0 and later, you can test retried event messages by calling Test.EventBus.deliver() and inspecting EventBusSubscriber fields.
See Also