summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testrule/EnableTestTracing.java
blob: aca398271d030f9cd4c8c0090039890a2521c662 (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
37
38
39
40
41
42
43
44
package com.mapbox.mapboxsdk.testrule;

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.
 *
 * 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).
 *
 * <pre>
 * @Rule
 * public EnableTestTracing mEnableTestTracing = new EnableTestTracing();
 * </pre>
 */
public class EnableTestTracing extends ExternalResource {

  private String mTestName;

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

  @Override
  public void before() {
    if (android.os.Build.VERSION.SDK_INT >= 18) {
      Trace.beginSection(mTestName);
    }
  }

  @Override
  public void after() {
    if (android.os.Build.VERSION.SDK_INT >= 18) {
      Trace.endSection();
    }
  }
}