leakcanary-android-instrumentation / leakcanary / FailTestOnLeakRunListener

FailTestOnLeakRunListener

open class FailTestOnLeakRunListener : RunListener

A JUnit RunListener that uses InstrumentationLeakDetector to detect memory leaks in Android instrumentation tests. It waits for the end of a test, and if the test succeeds then it will look for retained objects, trigger a heap dump if needed and perform an analysis.

FailTestOnLeakRunListener can be subclassed to override skipLeakDetectionReason and onAnalysisPerformed

See Also

InstrumentationLeakDetector

Constructors

NameSummary
<init>FailTestOnLeakRunListener()
A JUnit RunListener that uses InstrumentationLeakDetector to detect memory leaks in Android instrumentation tests. It waits for the end of a test, and if the test succeeds then it will look for retained objects, trigger a heap dump if needed and perform an analysis.

Functions

NameSummary
failTestfun failTest(trace: String): Unit
Reports that the test has failed, with the provided trace.
onAnalysisPerformedopen fun onAnalysisPerformed(heapAnalysis: HeapAnalysis): Unit
Called when a heap analysis has been performed and a result is available.
skipLeakDetectionReasonopen fun skipLeakDetectionReason(description: Description): String?
Can be overridden to skip leak detection based on the description provided when a test is started. Return null to continue leak detection, or a string describing the reason for skipping otherwise.
testAssumptionFailureopen fun testAssumptionFailure(failure: Failure): Unit
testFailureopen fun testFailure(failure: Failure): Unit
testFinishedopen fun testFinished(description: Description): Unit
testIgnoredopen fun testIgnored(description: Description): Unit
testRunFinishedopen fun testRunFinished(result: Result): Unit
testRunStartedopen fun testRunStarted(description: Description): Unit
testStartedopen fun testStarted(description: Description): Unit

Inheritors

NameSummary
FailAnnotatedTestOnLeakRunListenerclass FailAnnotatedTestOnLeakRunListener : FailTestOnLeakRunListener
A JUnit RunListener extending FailTestOnLeakRunListener to detecting memory leaks in Android instrumentation tests only when the FailTestOnLeak annotation is used.