22

If you have a test set to SeeAllData=true, and you publish a platform event that has a trigger that inserts a record, will that data actually be created in the org?

trigger PlatformEvent on NameSpace__PlatformEvent__e (after insert) {        
    insert new Account(Name='created from a test');
}

@IsTest(SeeAllData=true)
public class Test_PlatformEvent{
    @isTest
    public static void runTest(){
        Test.startTest();
        NameSpace__PlatformEvent__e event = new NameSpace__PlatformEvent__e();
        EventBus.publish(event);
        Test.stopTest();
    }       
}
  • 12
    You know what? It did leak data. I'm going to go tell some people now. – sfdcfox Sep 30 '17 at 4:14
  • So in this case inserted account will exist after finish of test execution? – Oleksandr Berehovskyi Sep 30 '17 at 5:34
  • 3
    @AlexanderBerehovskiy yes. I have a reproducible example in my dev org. Tried it a few times to verify that I'm not crazy. – sfdcfox Sep 30 '17 at 5:37
  • @sfdcfox - do you know if this was ever fixed? – Eric Dec 29 '17 at 1:45
  • 2
    @Eric It appears that the bug has been resolved. I ran the test just now, and no data was leaked. – sfdcfox Dec 29 '17 at 3:09
1

It is possible to set up data that will be global for all test methods.

Use @testSetup annotation for ONE static method inside the test class.

This method will be called before all the test methods in its own scope of limits and create required data.

Your test methods in their turn must query the data they need.

See Using Test Setup Methods for more details.

  • It has nothing to with test environment. There was bug in SF that caused platform event data to leak in actual data which is discussed in comment section. – Pranay Jaiswal May 8 '18 at 9:06
  • @PranayJaiswal, you are right - I was mislead by the question in the subject – Vladimir Egikyan May 8 '18 at 9:21
-1

Click here to see the details, another discussion with the same topic. Test Class SeeAllData=true Annotation

It never creates or executes any DML on your org data, marking seeAllData=true opens up the access to data but any data you are creating/modifying in test class stays till scope of test class.

-1

At the end of any test, all DML operations are rolled back, so even with seeAllData none of your production data should be changed.

This is because all test classes need to be run in production during deployments, and no one wants tests interfering with live data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.