+ Start a Discussion

Installation Issue : Create User Restriction on Code Coverage

I'm making my code coverage and I run into problems while I was trying to test the permissions. In my application the user have profiles and depend on each profiles, is the level of security of my records.
So first I run the code with a system administration (who has all the permission), and then I have to run the test (using System.runAs) with a non-system administrator, that enter to another parts of the code because that user don't have permission to do certain thinks.
Well may problem here is when I have only user in the org, or all the users are System Administration. Also I wasn't able to create new user in my test methods. There is some work around this or to create an user in my test methods??
Thanks in advance,
developer orgs give you two user accounts.  just set one of them to not be an administrator, and run the test as them.
Hi,I know that... but if our customer is trying to install my application in their org and they don't have or don't want to have a non system admin user in the system?
At some point (maybe it's already happened?), Salesforce will/has release(d) the ability to create "phantom" users in test code, to allow you to complete code coverage without depending on the presence of a user or license type being present in the system prior to installation. Try creating the new user in your test code, then using RunAs on the newly created user. Of course, this user is in a non-committed state, so as soon as the test expires, the user will cease to exist.