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
Rabbani sayyed 8Rabbani sayyed 8 

hi, what is test.isruntest() in test class? can anyone help me on this why and where we use this method?

Rajiv Bhatt 16Rajiv Bhatt 16
I think you mean Test.IsRunningTest() method. From the docs available @ https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm#apex_System_Test_isRunningTest 

"Returns true if the currently executing code was called by code contained in a test method, false otherwise. Use this method if you need to run different code depending on whether it was being called from a test."

This might be helpful sometimes to not execute certain blocks of you apex code. For ex: if you are calling a webservice in apex and you do not want it to the called when the testcase runs then you would simply wrap the callout with

// notice the NOT
if(!Test.isRunningTest()) {
//webservice callout
}
Sagar PareekSagar Pareek
This is used when you want to check if the code block is being called by a test class. For example you want to assign a specific value to a variable when test classes are running . 

If(Test.isRunningTest()){
variableOne = 2;

}