In Apex we can check if code is being called from an apex test class by using the method Test.isRunningTest().
Test.isRunningTest() returns true if the code is being executed by code in a test method otherwise it returns false. This lets us run code differently for real use cases and unit Tests.
//Check if a test is running
//Run specific logic for Tests
//Check if test is NOT Running
//Run specific logic that wont run in tests
A quick list of scenario's where the Test.isRunningTest() can be used are,
Testing HTTP Requests/Callouts to the external systems.
To bypass the error log creation in unit tests to improve performance.
To disable the triggers to avoid hitting the governor limits.
Something to keep an eye on when using the isRunningTest() is Code Coverage. You will not get code coverage for any code that's not covered in your unit tests. Therefore, if you overuse the isRunningTest() your code coverage may be in danger of falling below 75%.