1

My question is about a strategy for unit testing across profiles. Ideally, we'd like to isolate data to our unit tests (SeeAllData=false, the default) so that we could more easily write our unit tests to not touch on production data. Many of our tests need to test as different running users, with different profiles, including the Sites user ([SiteName] Guest User).

For most internal and portal profiles, we can just create an instance of the user within the test. However, we also need to test the website guest user (anonymous sites users) and it seems like the only way to get this user is to query for it. The only way to query for a user is to have SeeAllData=true and this makes test data isolation pretty difficult.

Ideally, what we want to do is create a utility class for our tests that takes arguments to create or query for a new or existing user, respectively. Does anyone have an example of utility methods like this that they could share here or via github?

4

User should be available without needing SeeAllData=true. See http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_testing_data_access.htm?SearchType=Stem

You can access: - User - Profile - Organization - RecordType - ApexClass - ApexTrigger - ApexComponent - ApexPage

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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