@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;
    }
  }
  @LocalData
  @Test
  public void setDescription() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);

    CaseResult caseResult = build.getAction(TestResultAction.class).getFailedTests().get(0);
    String url =
        build.getUrl()
            + "/testReport/"
            + caseResult.getRelativePathFrom(caseResult.getTestResult());

    testSetDescription(url, caseResult);

    ClassResult classResult = caseResult.getParent();
    url =
        build.getUrl()
            + "/testReport/"
            + classResult.getParent().getSafeName()
            + "/"
            + classResult.getSafeName();
    testSetDescription(url, classResult);

    PackageResult packageResult = classResult.getParent();
    url = build.getUrl() + "/testReport/" + classResult.getParent().getSafeName();
    testSetDescription(url, packageResult);
  }
 /**
  * @param caseResult the case result
  * @return NOT_RUN in case it is skipped, PASSED if it passed, and FAILED otherwise
  */
 private ExecutionStatus getExecutionStatus(CaseResult caseResult) {
   if (caseResult.isSkipped()) {
     return ExecutionStatus.NOT_RUN;
   } else if (caseResult.isPassed()) {
     return ExecutionStatus.PASSED;
   } else {
     return ExecutionStatus.FAILED;
   }
 }
Example #4
0
 public void freeze(SuiteResult parent) {
   this.parent = parent;
   // some old test data doesn't have failedSince value set, so for those compute them.
   if (!isPassed() && failedSince == 0) {
     CaseResult prev = getPreviousResult();
     if (prev != null && !prev.isPassed()) this.failedSince = prev.failedSince;
     else this.failedSince = getOwner().getNumber();
   }
 }
Example #5
0
  /**
   * When the testcase fails to initialize (exception in constructor or @Before) there is no
   * 'testcase' element at all.
   */
  @Bug(6700)
  public void testErrorInTestInitialization() throws Exception {
    SuiteResult suiteResult = parseOne(getDataFile("junit-report-6700.xml"));

    assertEquals(1, suiteResult.getCases().size());

    CaseResult result = suiteResult.getCases().get(0);
    assertEquals(1, result.getFailCount());
    assertTrue(result.getErrorStackTrace() != null);
  }
Example #6
0
  public void testErrorDetails() throws Exception {
    SuiteResult result = parseOne(getDataFile("junit-report-errror-details.xml"));

    List<CaseResult> cases = result.getCases();
    for (CaseResult caseResult : cases) {
      assertEquals(
          "Test class name is incorrect in " + caseResult.getDisplayName(),
          "some.package.somewhere.WhooHoo",
          caseResult.getClassName());
    }
    assertEquals(
        "this normally has the string like, expected mullet, but got bream",
        cases.get(0).getErrorDetails());
  }
Example #7
0
 /** If this test failed, then return the build number when this test started failing. */
 @Exported(visibility = 9)
 public int getFailedSince() {
   // If we haven't calculated failedSince yet, and we should,
   // do it now.
   if (failedSince == 0 && getFailCount() == 1) {
     CaseResult prev = getPreviousResult();
     if (prev != null && !prev.isPassed()) this.failedSince = prev.failedSince;
     else if (getOwner() != null) {
       this.failedSince = getOwner().getNumber();
     } else {
       LOGGER.warning("trouble calculating getFailedSince. We've got prev, but no owner.");
       // failedSince will be 0, which isn't correct.
     }
   }
   return failedSince;
 }
Example #8
0
  @Exported(name = "status", visibility = 9) // because stapler notices suffix 's' and remove it
  public Status getStatus() {
    if (skipped) {
      return Status.SKIPPED;
    }
    CaseResult pr = getPreviousResult();
    if (pr == null) {
      return isPassed() ? Status.PASSED : Status.FAILED;
    }

    if (pr.isPassed()) {
      return isPassed() ? Status.PASSED : Status.REGRESSION;
    } else {
      return isPassed() ? Status.FIXED : Status.FAILED;
    }
  }
Example #9
0
 /** Recount my children. */
 @Override
 public void tally() {
   passCount = failCount = skipCount = 0;
   duration = 0;
   for (CaseResult r : cases) {
     r.setClass(this);
     if (r.isSkipped()) {
       skipCount++;
     } else if (r.isPassed()) {
       passCount++;
     } else {
       failCount++;
     }
     // retrieve the class duration from these cases' suite time
     if (duration == 0) {
       duration = r.getSuiteResult().getDuration();
     }
   }
 }
Example #10
0
  /**
   * Verifying fix for issue #1463. JUnit report file is generated by SoapUI Pro 1.7.6
   * https://hudson.dev.java.net/issues/show_bug.cgi?id=1463
   */
  public void testIssue1463() throws Exception {
    SuiteResult result = parseOne(getDataFile("junit-report-1463.xml"));

    List<CaseResult> cases = result.getCases();
    for (CaseResult caseResult : cases) {
      assertEquals(
          "Test class name is incorrect in " + caseResult.getDisplayName(),
          "WLI-FI-Tests-Fake",
          caseResult.getClassName());
    }
    assertEquals(
        "Test name is incorrect", "IF_importTradeConfirmationToDwh", cases.get(0).getName());
    assertEquals("Test name is incorrect", "IF_getAmartaDisbursements", cases.get(1).getName());
    assertEquals("Test name is incorrect", "IF_importGLReconDataToDwh", cases.get(2).getName());
    assertEquals(
        "Test name is incorrect", "IF_importTradeInstructionsToDwh", cases.get(3).getName());
    assertEquals(
        "Test name is incorrect", "IF_getDeviationTradeInstructions", cases.get(4).getName());
    assertEquals("Test name is incorrect", "IF_getDwhGLData", cases.get(5).getName());
  }
  /* (non-Javadoc)
   * @see hudson.plugins.testlink.result.ResultSeeker#seekAndUpdate(hudson.plugins.testlink.result.TestCaseWrapper<?>[], hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener, hudson.plugins.testlink.TestLinkSite, hudson.plugins.testlink.result.Report)
   */
  @Override
  public void seek(
      TestCaseWrapper[] automatedTestCases,
      AbstractBuild<?, ?> build,
      Launcher launcher,
      BuildListener listener,
      TestLinkSite testlink)
      throws ResultSeekerException {
    listener.getLogger().println(Messages.Results_JUnit_LookingForTestCases()); // i18n
    try {
      final JUnitParser parser = new JUnitParser(false);
      final TestResult testResult = parser.parse(this.includePattern, build, launcher, listener);

      for (SuiteResult suiteResult : testResult.getSuites()) {
        for (CaseResult caseResult : suiteResult.getCases()) {
          for (TestCaseWrapper automatedTestCase : automatedTestCases) {
            final String[] commaSeparatedValues =
                automatedTestCase.getKeyCustomFieldValues(this.keyCustomField);
            for (String value : commaSeparatedValues) {
              if (!caseResult.isSkipped() && caseResult.getName().equals(value)) {
                ExecutionStatus status = this.getExecutionStatus(caseResult);
                automatedTestCase.addCustomFieldAndStatus(value, status);

                if (this.isIncludeNotes()) {
                  final String notes = this.getJUnitNotes(caseResult, build.number);
                  automatedTestCase.appendNotes(notes);
                }
                super.handleResult(automatedTestCase, build, listener, testlink, suiteResult);
              }
            }
          }
        }
      }
    } catch (IOException e) {
      throw new ResultSeekerException(e);
    } catch (InterruptedException e) {
      throw new ResultSeekerException(e);
    }
  }
  @Override
  public boolean trigger(AbstractBuild<?, ?> build, TaskListener listener) {
    AbstractBuild<?, ?> previousBuild = ExtendedEmailPublisher.getPreviousBuild(build, listener);
    if (previousBuild == null) return build.getResult() == Result.FAILURE;

    if (build.getAction(AbstractTestResultAction.class) == null) return false;

    // if previous run didn't have test results and this one does (with failures)
    if (previousBuild.getAction(AbstractTestResultAction.class) == null)
      return build.getAction(AbstractTestResultAction.class).getFailCount() > 0;

    // if more tests failed during this run
    if (build.getAction(AbstractTestResultAction.class).getFailCount()
        > previousBuild.getAction(AbstractTestResultAction.class).getFailCount()) return true;

    // if any test failed this time, but not last time
    for (Object result : build.getAction(AbstractTestResultAction.class).getFailedTests()) {
      CaseResult res = (CaseResult) result;
      if (res.getAge() == 1) return true;
    }

    return false;
  }
    @Override
    public List<TestAction> getTestAction(TestObject testObject) {
      String id = testObject.getId();
      ClaimTestAction result = claims.get(id);

      // In Hudson 1.347 or so, IDs changed, and a junit/ prefix was added.
      // Attempt to fix this backward-incompatibility
      if (result == null && id.startsWith("junit")) {
        result = claims.get(id.substring(5));
      }

      if (result != null) {
        return Collections.<TestAction>singletonList(result);
      }

      if (testObject instanceof CaseResult) {
        CaseResult cr = (CaseResult) testObject;
        if (!cr.isPassed() && !cr.isSkipped()) {
          return Collections.<TestAction>singletonList(new ClaimTestAction(this, id));
        }
      }

      return Collections.emptyList();
    }
  /**
   * 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();
  }
  @Override
  public Data getTestData(
      AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, TestResult testResult) {

    Data data = new Data(build);

    for (CaseResult result : testResult.getFailedTests()) {
      CaseResult previous = result.getPreviousResult();
      if (previous != null) {
        ClaimTestAction previousAction = previous.getTestAction(ClaimTestAction.class);
        if (previousAction != null && previousAction.isClaimed() && previousAction.isSticky()) {
          ClaimTestAction action = new ClaimTestAction(data, result.getId());
          previousAction.copyTo(action);
          data.addClaim(result.getId(), action);
        }
      }
    }

    return data;
  }
 public AbstractBuild<?, ?> getBuild() {
   return parent.getOwner();
 }
Example #17
0
 public CaseResult getCaseResult(String name) {
   for (CaseResult c : cases) {
     if (c.getSafeName().equals(name)) return c;
   }
   return null;
 }
 /**
  * Returns the result of this test case for the given build id. True if passed.
  *
  * @author dzhang29
  * @author jmullin2
  * @param build_id
  * @return Boolean
  */
 public Boolean getResult(int build_id) {
   CaseResult result = testHistory.get(build_id).testCase;
   return result.isPassed();
 }
Example #19
0
 public int compare(CaseResult lhs, CaseResult rhs) {
   return lhs.getAge() - rhs.getAge();
 }
Example #20
0
 public int compareTo(CaseResult that) {
   return this.getFullName().compareTo(that.getFullName());
 }
 @Override
 public boolean apply(CaseResult input) {
   return !input.isFailed();
 }