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
madhumadhu 

what is isrunningtest?? please explain with example???

what is isrunningtest?? please explain with example???
Ravi NarayananRavi Narayanan

public class test

{
public string check;

public void testttt()

{

if(test.isRunningTest())
check='Test';
else
check='tyftdytfyudd';
}
}


if this class is run using Testmethods, the value of check will be TEST. if it runs in normal mode, it will give ttytyytyt

MithunPMithunP
Hi Madhu,

Testing callouts is a bit trickier though. Basically in your callout code you check to see if you're executing within a unit test context by checking Test.isRunningTest() and instead of getting your callout response from an HttpResponse.send() request, you return a pre-built test string instead. There's also an older example of callout unit testing that uses a static variable you set in your unit test. Just replace that static variable with a call to Test.isRunningTest() and their example works fairly well as well.

Please refer following links for detail information
http://michaelwelburn.com/2014/03/03/a-better-way-to-use-test-isrunningtest-in-apex/
http://salesforce.stackexchange.com/questions/9888/triggering-a-dml-exception-for-test-coverage

http://www.iterativelogic.com/unit-test-callouts-in-apex-code-part-2/

Best Regards,
Mithun.