TestBroker Class

Contains a method that delivers platform event or change event messages in an Apex test.

Namespace

EventBus

TestBroker Methods

The following are methods for TestBroker.

deliver()

Delivers platform event messages to the test event bus. Use this method to deliver test event messages multiple times and verify that event subscribers have processed the test events each step of the way.

Signature

public void deliver()

Return Value

Type: void

Usage

Enclose Test.getEventBus().deliver() within the Test.startTest() and Test.stopTest() statement block.

Test.startTest();
// Create test events
// ...
// Publish test events with EventBus.publish()
// ...
// Deliver test events
Test.getEventBus().deliver();
// Perform validation 
// ...
Test.stopTest();