Summary: Ctors | Methods | Inherited Methods | [Expand All]

# LogBatteryInformationRule

`public class LogBatteryInformationRule`
`` `` `extends LoggingBaseRule` ``

java.lang.Object
↳ | org.junit.rules.ExternalResource
| ↳ | android.support.test.rule.logging.LoggingBaseRule
|  | ↳ | android.support.test.rule.logging.LogBatteryInformationRule

When applied to a test class this `Rule` resets battery information ("stats") before test method execution. The `Rule` then collects battery information after test method execution and logs it to a file on external storage. The default file location is maintained at `getTestDir(String, String, int)`. The Rule performs these actions through the execution of a dumpsys on the `batterystats` service.

If the API level is less than 21 (Lollipop) this rule will do nothing since this dumpsys command isn't supported. This TestRule has limited use for short running tests and is meant for very long running tests.

The `Rule`'s `before()` and `after()` methods can also be used for logging battery information across a test suite by manually invoking the methods in a `RunListener`.

Usage: `\@Rule public LogBatteryInformationRule mLogBatteryInformationRule = new LogBatteryInformationRule(); `

## Summary

### Public constructors
`LogBatteryInformationRule()`
`LogBatteryInformationRule(File logFileOutputDirectory, String fileName)`

### Public methods
`void` | `afterTest()`
`void` | `beforeTest()`
`String` | `getDefaultLogFileName()` Return the default log file name for this rule class.

### Inherited methods
From class `android.support.test.rule.logging.LoggingBaseRule`
`final void` | `after()`
`final Statement` | `apply(Statement base, Description description)`
`final void` | `before()`
`String` | `getLogFileName()`
`File` | `getLogFileOutputDirectory()`
`String` | `getPackageNameUnderTest()`
`String` | `getTestClass()`
`String` | `getTestName()`
`int` | `getTestRunNumber()`
`void` | `setTestRunNumber(int testRunNumber)` Indicate to the `Rule` that this is the `testRunNumber`th time the test method is being called in a test instrumentation.
From class `org.junit.rules.ExternalResource`
`void` | `after()`
`Statement` | `apply(Statement arg0, Description arg1)`
`void` | `before()`
From class `java.lang.Object`
`Object` | `clone()`
`boolean` | `equals(Object arg0)`
`void` | `finalize()`
`final Class<?>` | `getClass()`
`int` | `hashCode()`
`final void` | `notify()`
`final void` | `notifyAll()`
`String` | `toString()`
`final void` | `wait(long arg0, int arg1)`
`final void` | `wait(long arg0)`
`final void` | `wait()`
From interface `org.junit.rules.TestRule`
`abstract Statement` | `apply(Statement arg0, Description arg1)`

## Public constructors

### LogBatteryInformationRule

    LogBatteryInformationRule ()

### LogBatteryInformationRule

    LogBatteryInformationRule (File logFileOutputDirectory,
                    String fileName)

Parameters
`logFileOutputDirectory` | `File`
`fileName` | `String`

## Public methods

### afterTest

    void afterTest ()

### beforeTest

    void beforeTest ()

### getDefaultLogFileName

    String getDefaultLogFileName ()

Return the default log file name for this rule class. A null return value indicates the rule doesn't log to a file.

Returns
`String` |

``

- ## Classes

  - AtraceLogger
  - EnableTestTracingRule
  - LogBatteryInformationRule
  - LogDeviceGetPropInfoRule
  - LoggingBaseRule
  - LogGraphicsStatsRule
  - LogLogcatRule
  - LogNetStatsRule
  - RuleLoggingUtils