Is there any way to mock and test Salesforce Streaming? How do you test Salesforce Streaming API ?
1 Answer
Yes. It is possible.
@isTest static void testPlatformEvent() {
SomeEvent__e event = new SomeEvent__e(SomeField='test');
Test.startTest();
Database.SaveResult sr = EventBus.publish(event);
Test.stopTest();
System.assertEquals(true, sr.isSuccess());
For more information read Salesforce guide
-
this testmethod, while correct, actually tests nothing of interest. By definition,
EventBus.publish(event)
will always work in the test context provided you are not publishing more than 500 events. Consumption of the event is what one would test in a testmethod and that requires the org to have a subscriber (trigger/PB/flow) that leaves some persistence behind to asset against– cropredyCommented Dec 10, 2019 at 18:51