Disabling logger in a test context #484
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @alanjaouen - any chance you could provide a sample of what your test is doing / how you're calling Another way to approach it is to create a @IsTest
private static void runsSomeTest() {
LoggerSettings__c settings = LoggerSettings__c.getOrgDefaults();
settings.IsEnabled__c = false;
insert settings;
// TODO add your test here - logging will now be disabled in this test method
} |
Beta Was this translation helpful? Give feedback.
-
Hi @jongpie here is a sample of what i'm doing @isTest(isParallel=true)
public class myTestClass {
@testSetup
public static void setup() {
// disable log saving
Logger.suspendSaving();
}
@isTest
public static void convertInvoiceToJsonWithOneId() {
// Given - data
Id id = fflib_IDGenerator.generate(blng__Invoice__c.SObjectType);
Set<Id> invoiceIds = new Set<Id>{ id };
// When
String returned = new myService().MyMethod(invoiceIds);
// Then
// some asserts
}
...
} For what I see, we insert events |
Beta Was this translation helpful? Give feedback.
Hi @alanjaouen - using
Logger.suspendSaving()
within@TestSetup
won't work unfortunately, due to how Apex resets some transaction limits & variables before running your@IsTest
method. You could instead use this in your@TestSetup
method to disable logging in all of your tests: