Class StaticFieldsInvariantRule

java.lang.Object
com.carrotsearch.randomizedtesting.rules.StaticFieldsInvariantRule
All Implemented Interfaces:
org.junit.rules.TestRule

public class StaticFieldsInvariantRule extends Object implements org.junit.rules.TestRule
A TestRule that ensures static, reference fields of the suite class (and optionally its superclasses) are cleaned up after a suite is completed. This is helpful in finding out static memory leaks (a class references something huge but is no longer used).
See Also:
  • Field Details

    • DEFAULT_LEAK_THRESHOLD

      public static final long DEFAULT_LEAK_THRESHOLD
      See Also:
    • leakThreshold

      private final long leakThreshold
    • countSuperclasses

      private final boolean countSuperclasses
  • Constructor Details

    • StaticFieldsInvariantRule

      public StaticFieldsInvariantRule()
      By default use DEFAULT_LEAK_THRESHOLD as the threshold and count in superclasses.
    • StaticFieldsInvariantRule

      public StaticFieldsInvariantRule(long leakThresholdBytes, boolean countSuperclasses)
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement s, org.junit.runner.Description d)
      Specified by:
      apply in interface org.junit.rules.TestRule
    • accept

      protected boolean accept(Field field)
      Returns:
      Return false to exclude a given field from being counted. By default final fields are rejected.