Skip to content

Disabling logger in a test context #484

Answered by jongpie
alanjaouen asked this question in Q&A
Discussion options

You must be logged in to vote

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:

@isTest(isParallel=true)
public class myTestClass {
    @testSetup
    public static void setup() {
        // disable log saving
        LoggerSettings__c settings = LoggerSettings__c.getOrgDefaults();
        settings.IsEnabled__c = false;
        upsert settings;
    }

    @isTest
    public static void convertInvoiceToJsonWithOneId() {
        // Given - data
        Id id = fflib_IDGenerator.generate(blng__In…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jongpie
Comment options

Answer selected by alanjaouen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants