The question is simple: should test classes be defined with sharing with sharing | without sharing | inherited sharing to pass the security review?

Technically Salesforce enforces this by saying it in their documentation:

Mark all (non-interface) classes as either with sharing, without sharing, or inherited sharing.

Yet it seems redundant for test classes. If it really needs to be, then why?

1 Answer 1


Test classes does not have concept of sharing because you would never use test class to get/post/delete/other DML/queries in test class/methods.

But, you would use test classes and its methods to check whether record accessibility for view/read/delete is as per business specifications in given Apex classes

  • 3
    I don't think I agree here. Test class behavior can definitely change based on whether or not the class is declared with sharing.
    – David Reed
    Jul 23, 2019 at 17:43
  • So does the security review team require test classes to be declared with sharing specification?
    – Eduard
    Jul 24, 2019 at 7:19

You must log in to answer this question.

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