Apex 테스트 메서드에서 테스트 데이터를 설정할 때 시작 트리거를 비활성화하는 방법이 필요합니다. 이로 인해 "LimitException: "Too many SOQL queries: 101" 오류가 발생할 수 있습니다. 이 경우 트리거는 테스트 케이스의 대상이 아니므로 이 시나리오에서는 테스트 메서드가 실패합니다. 모든 테스트 케이스에서 트리거를 무효로 할 필요는 없고, 대신에 isRunningTest() 를 사용할 수 있습니다.
isRunningTest()를 활용하여 트리거를 설정합니다. isRunningTest()는 현재 실행되고 있는 코드가 테스트 메서드에 포함되어 있는 코드로부터 호출된 경우는 true를 반환하고 그렇지 않으면 false를 반환합니다. 이 메서드는 테스트에서 호출되었는지 여부에 따라 다른 코드를 실행해야 하는 경우에 사용합니다.
Test.isRunningTest 코드 예시
if(Test.isRunningTest()){
//동작 실행
}
다른 시나리오
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.