TritonTestFactory
Shared @IsTest helper for setting up, building, flushing, and asserting Triton logs in your own test classes.
Overview
TritonTestFactory is an @IsTest utility that consolidates the setup, record-creation, flush, query, and assertion helpers used across Triton's own tests. You can reuse it in your test classes to reduce boilerplate when exercising Triton logging.
Setup & State
initTestSetup()
public static void initTestSetup()Standard test setup — initializes Pharos test settings and clears the Log_Level__mdt cache. Call from your @TestSetup.
resetFlowState()
public static void resetFlowState()Resets Flow-related static state: the TritonFlowFlushBatch pending buffer and the TritonCacheManager mock cache.
Fault Injection
failPublishing()
public static void failPublishing()Makes every Triton publish in the current test fail, at the single path all publishing goes through. Use it to prove your code survives a publish that Pharos refuses: the logging calls still return normally, and nothing is persisted.
@IsTest
static void saveSurvivesAFailedPublish() {
TritonTestFactory.failPublishing();
Test.startTest();
insert new Account(Name = 'Acme'); // the instrumented trigger logs and flushes
Test.stopTest();
System.assertEquals(1, [SELECT COUNT() FROM Account]);
TritonTestFactory.assertNoLogs();
}restrictLevel(TritonTypes.Level l)
Installs a single global Log_Level__mdt rule at level l, so every log more verbose than it is filtered out. Tests start with no Log_Level__mdt rules (the org's own are never loaded), so this one rule is the only filter for the rest of the test.
Record Creation
makeFlowLog(String summary)
Creates a TritonFlow.FlowLog with standard test defaults (category Flow, type type, area area).
makeLogRecord(String summary)
Creates a pharos__Log__c record with standard test defaults.
Flush
flushCachedFlowLogs()
Manually drains cached Flow logs by constructing a TritonFlowFlushBatch and executing it — needed because a delayed System.scheduleBatch does not run during Test.stopTest().
Assertions
assertNoLogs()
Asserts that no pharos__Log__c records exist.
assertLogCount(Integer expected)
Asserts that exactly expected log records exist.
assertSingleLog(TritonTypes.Category expectedCategory)
Asserts exactly one log exists with a populated hash and returns it.
Query Helpers
queryLogs()
Returns all pharos__Log__c records with the commonly queried fields, ordered by creation date.
countFlowFlushBatchJobs()
Returns the count of TritonFlowFlushBatch async apex jobs.
countActiveFlowFlushBatchJobs()
Returns the count of active (queued/processing) TritonFlowFlushBatch jobs.
Last updated