When we are setting up test data from an Apex test method, we need a way to disable the triggers that will fire because it might cause "LimitException: "Too many SOQL queries: 101". In this case, the triggers are not the target of the test case, hence this situation will cause the test method to fail. It is not necessary to disable the trigger for every test case, instead we can use isRunningTest().
Setup up the trigger by using isRunningTest(). The isRunningTest() call 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.
Example Test.isRunningTest code
if(Test.isRunningTest()){
//do something
}
Other Usage Scenarios
1. To ensure the trigger doesn't execute the batch if Test.IsRunningTest() is true, and then test the batch class with it's own test method.
2. In your testing 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 a HttpResponse.send() request, you return a prebuilt test string instead.
3. System.purgeOldAsyncJobs if called within this context, can cause long executions based on data to be purged. Here, using Test.isRunningTest() can help.
Idea Exchange: Warn if a new Apex Class (Test) will override a Salesforce Apex Class
000386600

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.