ApexBeginnertestingantipatterns
Use Test.isRunningTest branching carefully
Real World Scenario
Code skips callout in test via Test.isRunningTest but production callout failure path never tested.
Expected Answer
• Prefer HttpCalloutMock over skipping logic in tests
• Test.isRunningTest for metadata unavailable in test only as last resort
• Document any isRunningTest branch with ticket to remove
• Assert mock callout responses not empty stubs
• Cover failure paths with mock 500 responses
• Code review flag isRunningTest in production logic
• Use @TestVisible for test seam injection instead
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Direct answer: Prefer HttpCalloutMock over skipping logic in tests Also consider: Test.isRunningTest for metadata unavailable in test only as last resort In practice: Document any isRunningTest branch with ticket to remove Keep the solution simple and well-documented for the team.
Architect Perspective
Test.isRunningTest in business logic is code smell—mock dependencies instead.