You need to sign in to do that
Don't have an account?
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.
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.

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).