コード例 #1
0
ファイル: CaseResult.java プロジェクト: kutzi/jenkins
 @Override
 public AbstractBuild<?, ?> getOwner() {
   SuiteResult sr = getSuiteResult();
   if (sr == null) {
     LOGGER.warning("In getOwner(), getSuiteResult is null");
     return null;
   }
   hudson.tasks.junit.TestResult tr = sr.getParent();
   if (tr == null) {
     LOGGER.warning("In getOwner(), suiteResult.getParent() is null.");
     return null;
   }
   return tr.getOwner();
 }
コード例 #2
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;
    }
  }
コード例 #3
0
  /**
   * Record the test results into the current build.
   *
   * @param junitFilePattern
   * @param build
   * @param listener
   * @return
   * @throws InterruptedException
   * @throws IOException
   */
  private boolean recordTestResult(
      String junitFilePattern, AbstractBuild<?, ?> build, BuildListener listener)
      throws InterruptedException, IOException {
    TestResultAction existingAction = build.getAction(TestResultAction.class);
    TestResultAction action;

    try {
      final long buildTime = build.getTimestamp().getTimeInMillis();

      TestResult existingTestResults = null;
      if (existingAction != null) {
        existingTestResults = existingAction.getResult();
      }
      TestResult result = getTestResult(junitFilePattern, build, existingTestResults, buildTime);

      if (existingAction == null) {
        action = new TestResultAction(build, result, listener);
      } else {
        action = existingAction;
        action.setResult(result, listener);
      }
      if (result.getPassCount() == 0 && result.getFailCount() == 0)
        new AbortException("None of the test reports contained any result");
    } catch (AbortException e) {
      if (build.getResult() == Result.FAILURE)
        // most likely a build failed before it gets to the test phase.
        // don't report confusing error message.
        return true;

      listener.getLogger().println(e.getMessage());
      build.setResult(Result.FAILURE);
      return true;
    }

    if (existingAction == null) {
      build.getActions().add(action);
    }

    if (action.getResult().getFailCount() > 0) build.setResult(Result.UNSTABLE);

    return true;
  }
コード例 #4
0
  /* (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);
    }
  }
コード例 #5
0
  @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;
  }