Activity Forums Salesforce® Discussions What is Test.isRunningTest() in Salesforce?

  • MOHIT

    Member
    February 19, 2020 at 6:28 am

    The Test.isRunningTest()  method is used to identify, if the piece of code being executed is invoked from a Test class execution or from other artefacts such as a Trigger, Bacth Job etc. Returns true if the code being executed is invoked from a test class otherwise returns a false.

    This method usually comes in handy, when you intend to conditionally restrict execution of certain Apex code blocks, based on whether they are being invoked from a test class or not. A practical example would be that performing web service callouts in Apex are not supported within Test Code. Hence you could use the Test.isRunningTest() to conditionally identify and route the execution of a code block that calls the Test Mock framework to simulate a mock, callout reponse.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos