@Override
  public void testRunEnded(long elapsedTime, Map<String, String> runMetrics) {
    getLog().info(deviceLogLinePrefix + INDENT + "Run ended: " + elapsedTime + " ms");
    if (hasFailuresOrErrors()) {
      getLog().error(deviceLogLinePrefix + INDENT + "FAILURES!!!");
    }
    getLog()
        .info(
            INDENT
                + "Tests run: "
                + testRunCount
                + (testRunCount < testCount ? " (of " + testCount + ")" : "")
                + ",  Failures: "
                + testFailureCount
                + ",  Errors: "
                + testErrorCount
                + ",  Ignored: "
                + testIgnoredCount);

    if (createReport) {
      report.setTests(Integer.toString(testCount));
      report.setFailures(Integer.toString(testFailureCount));
      report.setErrors(Integer.toString(testErrorCount));
      report.setSkipped(Integer.toString(testIgnoredCount));
      report.setTime(timeFormatter.format(elapsedTime / 1000.0));
    }

    logMetrics(runMetrics);

    if (createReport) {
      writeJunitReportToFile();
    }
  }
  @Override
  public void testRunStarted(String runName, int tCount) {
    if (takeScreenshotOnFailure) {
      executeOnAdbShell("rm -f " + screenshotsPathOnDevice + "/*screenshot.png");
      executeOnAdbShell("mkdir " + screenshotsPathOnDevice);
    }

    this.testCount = tCount;
    getLog()
        .info(
            deviceLogLinePrefix
                + INDENT
                + "Run started: "
                + runName
                + ", "
                + testCount
                + " tests:");

    if (createReport) {
      report = new Testsuite();
      report.setName(runName);
      final Testsuite.Properties props = new Testsuite.Properties();
      report.getProperties().add(props);
      for (Map.Entry<Object, Object> systemProperty : System.getProperties().entrySet()) {
        final Testsuite.Properties.Property property = new Testsuite.Properties.Property();
        property.setName(systemProperty.getKey().toString());
        property.setValue(systemProperty.getValue().toString());
        props.getProperty().add(property);
      }
      Map<String, String> deviceProperties = device.getProperties();
      for (Map.Entry<String, String> deviceProperty : deviceProperties.entrySet()) {
        final Testsuite.Properties.Property property = new Testsuite.Properties.Property();
        property.setName(deviceProperty.getKey());
        property.setValue(deviceProperty.getValue());
        props.getProperty().add(property);
      }
    }
  }
  @Override
  public void testEnded(TestIdentifier testIdentifier, Map<String, String> testMetrics) {
    getLog()
        .info(
            deviceLogLinePrefix
                + String.format(
                    "%1$s%1$sEnd [%2$d/%3$d]: %4$s",
                    INDENT, testRunCount, testCount, testIdentifier.toString()));
    logMetrics(testMetrics);

    if (createReport) {
      double seconds = (System.currentTimeMillis() - currentTestCaseStartTime) / 1000.0;
      currentTestCase.setTime(timeFormatter.format(seconds));
      report.getTestcase().add(currentTestCase);
    }
  }