I keep getting a System.UnexpectedException whenever I run unit tests for code that publishes Platform Events. As soon as I call Test.stopTest(), the test fails with System.UnexpectedException: Error processing messages
I have even tried writing a very simple unit test which also fails:
@isTest
private static void samplePublishApplicationUpdateEvent_justPublishingAnEvent_expectToLearnSomething() {
Application_Update__e updateEvent = new Application_Update__e();
updateEvent.Application_Id__c = '12345';
Test.startTest();
EventBus.publish(updateEvent);
Test.stopTest();
}
As soon as we hit Test.stopTest(), I receive the System.UnexpectedException failure.
The API version of the classes is 40. The user I am running the tests as has read/create permissions for my platform event.
Does anyone have any ideas?