function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VenkataRajaVenkataRaja 

System.runAs() is required to use whenever I created user in testMethod.

Hi,

I have batch class, will send email to perticular user in finish method. I am writing test class for this, and created one test user and getting class success and getting code coverage. As per standards, Is it required to test this in System.runAs()? If we create a test user in any test class is mandatory to use system.runAs(), In whcih situation we are able to use this method.
Best Answer chosen by VenkataRaja
bob_buzzardbob_buzzard
You'll need to use System.runAs() if you want to execute the test code as a user with a particular license/profile.  Otherwise the unit tests will run as whichever user executes the test (most likely a system administrator).