summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/rules/TraceRule.java
blob: bba65b447654ee1fda23cd77417daae0a5874b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.mapbox.mapboxsdk.rules;

import android.os.Trace;

import org.junit.rules.ExternalResource;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * This rule enables {@link Trace Tracing} for each test. The section name
 * used for the Trace API is the name of the test being run.
 * <p>
 * To enable AndroidTracing on a test simply add this rule like so and it will be enabled/disabled
 * when the platform support for Tracing exists (API Level 18 or higher).
 * <p>
 */
public class TraceRule extends ExternalResource {

  private String testName;

  @Override
  public Statement apply(Statement base, Description description) {
    testName = description.getMethodName();
    return super.apply(base, description);
  }

  @Override
  public void before() {
    Trace.beginSection(testName);
  }

  @Override
  public void after() {
    Trace.endSection();
  }
}