Exemplo n.º 1
0
  @Override
  public Data getTestData(AbstractBuild<?, ?> ab, Launcher lnchr, BuildListener bl, TestResult tr)
      throws IOException, InterruptedException {
    bl.getLogger().println("Scanning for test data...");
    boolean foundSession = false;
    List<String> sessionIDs = null;

    for (SuiteResult sr : tr.getSuites()) {
      for (CaseResult cr : sr.getCases()) {
        sessionIDs = TestingBotReportFactory.findSessionIDs(cr);
        if (!sessionIDs.isEmpty()) {
          String errorDetails = cr.getErrorDetails();
          if (errorDetails == null) {
            errorDetails = "";
          }
          TestingBotAPI api = new TestingBotAPI();
          Map<String, String> data = new HashMap<String, String>();
          data.put("success", cr.isPassed() ? "1" : "0");
          data.put("status_message", errorDetails);
          data.put("name", cr.getFullName());
          api.updateTest(sessionIDs.get(0), data);

          foundSession = true;
        }
      }
    }

    if (!foundSession) {
      bl.getLogger().println("No TestingBot sessionIDs found in test output.");
      return null;
    } else {
      return TestingBotReportFactory.INSTANCE;
    }
  }
  /**
   * Retrieves the Notes about the JUnit test.
   *
   * @param testCase JUnit test.
   * @return Notes about the JUnit test.
   */
  private String getJUnitNotes(CaseResult testCase, int buildNumber) {
    StringBuilder notes = new StringBuilder();
    notes.append(
        Messages.Results_JUnit_NotesForTestCase(
            testCase.getName(),
            testCase.getClassName(),
            testCase.getSkipCount(),
            testCase.getFailCount(),
            (testCase.getSuiteResult() != null ? testCase.getSuiteResult().getTimestamp() : null)));

    /* Added for appending build number and error message */
    notes.append("\nBuild no : " + buildNumber);
    if (null != testCase.getErrorDetails()) {
      notes.append("\nError Message : " + testCase.getErrorDetails());
    }

    return notes.toString();
  }