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
Sanu VermaSanu Verma 

How to Pass IsTestRunning Condition in Test Class

How to Cover test.isRunningTest() in test class in if else conditon
for(String ownerId : ownerIds){
                if(loggedInUsers != NULL && loggedInUsers.size() > 0){
                    String a;
                    if(test.isRunningTest() == true){
                         a = null;
                        System.debug(a);
                    }else{
                         a = ownerId;
                        System.debug(a);
                    }
Akshay_DhimanAkshay_Dhiman
Hi Sanu,

You have to use Test.IsRunningTest in your apex class, Not in Test class 

Test.IsRunningTest is basically used If we want to cover the scenario of a code of our apex class is being covered by your Test class.
I am Refer you the following links do check it once before applying to Test.IsRunningTest
Hope this might helps you
Test.isRunningTest() :

1. This is not used in test classes but in other classes in order to verify if the call is from a test class.
2.Test.isRunningTest() is used to define whether the code is executed by test class. 

Example :
 
public String Test(){
    // Build the http request
    // Invoke web service call
    String result = '';
    if (!Test.isRunningTest()){
        // Make a real callout since we are not running a test
    } else {
        // A test is running
        result = Response;
    }
    return result;
}



http://michaelwelburn.com/2014/03/03/a-better-way-to-use-test-isrunningtest-in-apex/

Thanks 
Akshay