Exemplo n.º 1
0
  /**
   * @param optionalValues TODO
   * @param finder TODO
   * @param parameterAnnotations TODO
   * @param m
   * @param instance
   * @return An array of parameters suitable to invoke this method, possibly picked from the
   *     property file
   */
  private static Object[] createParameters(
      String methodName,
      Class[] parameterTypes,
      String[] optionalValues,
      String methodAnnotation,
      IAnnotationFinder finder,
      String[] parameterNames,
      MethodParameters params,
      XmlSuite xmlSuite) {
    Object[] result = new Object[0];
    if (parameterTypes.length > 0) {
      List<Object> vResult = new ArrayList<Object>();

      checkParameterTypes(methodName, parameterTypes, methodAnnotation, parameterNames);

      for (int i = 0, j = 0; i < parameterTypes.length; i++) {
        if (Method.class.equals(parameterTypes[i])) {
          vResult.add(params.currentTestMethod);
        } else if (ITestContext.class.equals(parameterTypes[i])) {
          vResult.add(params.context);
        } else {
          if (j < parameterNames.length) {
            String p = parameterNames[j];
            String value = params.xmlParameters.get(p);
            if (null == value) {
              // try SysEnv entries
              value = System.getProperty(p);
            }
            if (null == value) {
              if (optionalValues != null) {
                value = optionalValues[i];
              }
              if (null == value) {
                throw new TestNGException(
                    "Parameter '"
                        + p
                        + "' is required by "
                        + methodAnnotation
                        + " on method "
                        + methodName
                        + "\nbut has not been marked @Optional or defined "
                        + (xmlSuite.getFileName() != null ? "in " + xmlSuite.getFileName() : ""));
              }
            }

            vResult.add(convertType(parameterTypes[i], value, p));
            j++;
          }
        }
      }

      result = (Object[]) vResult.toArray(new Object[vResult.size()]);
    }

    return result;
  }
Exemplo n.º 2
0
  /**
   * Runs a suite and its children suites
   *
   * @param result populates this list with execution results
   * @param suiteRunnerMap map of suiteRunners that are updated with test results
   * @param xmlSuite XML suites to run
   */
  private void runSuite(XmlSuite xmlSuite) {
    //    System.out.println("Running suite:" + xmlSuite);
    if (m_verbose > 0) {
      StringBuffer allFiles = new StringBuffer();
      allFiles
          .append("  ")
          .append(xmlSuite.getFileName() != null ? xmlSuite.getFileName() : m_defaultSuiteName)
          .append('\n');
      Utils.log("TestNG", 0, "Running:\n" + allFiles.toString());
    }

    PoolService.initialize(xmlSuite.getDataProviderThreadCount());
    //    for (XmlSuite s : suiteRunnerMap.keySet()) {
    //      System.out.println(s.equals(xmlSuite) + " " + s.hashCode() + " " + xmlSuite.hashCode());
    //    }
    m_suiteRunner.run();
    //    PoolService.getInstance().shutdown();

    //
    // Display the final statistics
    //
    int passed = 0;
    int failed = 0;
    int skipped = 0;
    int confFailures = 0;
    int confSkips = 0;
    int total = 0;
    if (xmlSuite.getVerbose() > 0) {
      //      SuiteResultCounts counts = new SuiteResultCounts();
      //      counts.calculateResultCounts(xmlSuite, suiteRunnerMap);
      m_verboseOutput =
          new StringBuilder("\n===============================================\n")
              .append(xmlSuite.getName());
      for (ISuiteResult isr : m_suiteRunner.getResults().values()) {
        passed += isr.getTestContext().getPassedTests().size();
        failed += isr.getTestContext().getFailedTests().size();
        skipped += isr.getTestContext().getSkippedTests().size();
        confFailures += isr.getTestContext().getFailedConfigurations().size();
        confSkips += isr.getTestContext().getSkippedConfigurations().size();
      }
      total += passed + failed + skipped;

      m_verboseOutput
          .append("\nTotal tests run: ")
          .append(total)
          .append(", Failures: ")
          .append(failed)
          .append(", Skips: ")
          .append(skipped);
      ;
      if (confFailures > 0 || confSkips > 0) {
        m_verboseOutput
            .append("\nConfiguration Failures: ")
            .append(confFailures)
            .append(", Skips: ")
            .append(confSkips);
      }
      m_verboseOutput.append("\n===============================================\n");

      System.out.println(m_verboseOutput);
    }
  }