0

Requirement:

I want to put a check on the code so that It should execute only when we are not running test cases.

Community
  • 1
  • 1

1 Answers1

0

You can use C#'s preprocessor directives for this.

void Start()
{
    #if (!TEST_CASE)
    //Your code
    Debug.Log("test cases");
    #endif
}

If you want the code in that Start function to execute, define it at the top of the script and before any using statement:

#define TEST_CASE 

using System;
using UnityEngine;

Because ! is used in the if statement, the code in that if statement will only execute when TEST_CASE is not defined. Simply comment it out if you need it to execute.

Programmer
  • 121,791
  • 22
  • 236
  • 328