2

Is there any way to mock and test Salesforce Streaming? How do you test Salesforce Streaming API ?

1
  • Be a bit more explicit here - what/who are the subscribers/consumers of the stream?
    – cropredy
    Commented Dec 10, 2019 at 18:52

1 Answer 1

1

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

1
  • 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
    – cropredy
    Commented Dec 10, 2019 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .