コード例 #1
0
ファイル: TestNGRunner.java プロジェクト: Addepar/buck
  private static String calculateTestMethodName(ITestResult iTestResult) {
    Object[] parameters = iTestResult.getParameters();
    String name = iTestResult.getName();

    if (parameters == null || parameters.length == 0) {
      return name;
    }

    StringBuilder builder = new StringBuilder(name).append(" (");
    for (int i = 0; i < parameters.length; i++) {
      Object parameter = parameters[i];
      if (parameter == null) {
        builder.append("null");
      } else {
        try {
          builder.append(parameter.toString());
        } catch (Exception e) {
          builder.append("Unstringable object");
        }
      }
      if (i < parameters.length - 1) {
        builder.append(", ");
      }
    }
    builder.append(")");
    return builder.toString();
  }
コード例 #2
0
 private void generateForResult(ITestResult ans, ITestNGMethod method, int resultSetSize) {
   Object[] parameters = ans.getParameters();
   boolean hasParameters = parameters != null && parameters.length > 0;
   if (hasParameters) {
     tableStart("result", null);
     m_out.print("<tr class=\"param\">");
     for (int x = 1; x <= parameters.length; x++) {
       m_out.print("<th>Parameter #" + x + "</th>");
     }
     m_out.println("</tr>");
     m_out.print("<tr class=\"param stripe\">");
     for (Object p : parameters) {
       m_out.println("<td>" + Utils.escapeHtml(p.toString()) + "</td>");
     }
     m_out.println("</tr>");
   }
   List<String> msgs = Reporter.getOutput(ans);
   boolean hasReporterOutput = msgs.size() > 0;
   Throwable exception = ans.getThrowable();
   boolean hasThrowable = exception != null;
   if (hasReporterOutput || hasThrowable) {
     if (hasParameters) {
       m_out.print("<tr><td");
       if (parameters.length > 1) {
         m_out.print(" colspan=\"" + parameters.length + "\"");
       }
       m_out.println(">");
     } else {
       m_out.println("<div>");
     }
     if (hasReporterOutput) {
       if (hasThrowable) {
         m_out.println("<h3>Test Messages</h3>");
       }
       for (String line : msgs) {
         m_out.println(line + "<br/>");
       }
     }
     if (hasThrowable) {
       boolean wantsMinimalOutput = ans.getStatus() == ITestResult.SUCCESS;
       if (hasReporterOutput) {
         m_out.println("<h3>" + (wantsMinimalOutput ? "Expected Exception" : "Failure") + "</h3>");
       }
       generateExceptionReport(exception, method);
     }
     if (hasParameters) {
       m_out.println("</td></tr>");
     } else {
       m_out.println("</div>");
     }
   }
   if (hasParameters) {
     m_out.println("</table>");
   }
 }
コード例 #3
0
 private void logEndOfTest(ITestResult result, String outcome) {
   logger.info(
       String.format(
           "Testing going to end for: %s.%s(%s) %s",
           result.getTestClass().getName(),
           result.getName(),
           Arrays.toString(result.getParameters()),
           outcome));
   NDC.pop();
   logLine();
 }
コード例 #4
0
 @Override
 public void onTestStart(ITestResult result) {
   logLine();
   logger.info(
       String.format(
           "Testing going to start for: %s.%s %s",
           result.getTestClass().getName(),
           result.getName(),
           Arrays.toString(result.getParameters())));
   NDC.push(result.getName());
 }
コード例 #5
0
ファイル: JUnitXMLReporter.java プロジェクト: xiongrl/JGroups
 protected static String getMethodName(ITestResult tr) {
   String method_name = tr.getName();
   Object[] params = tr.getParameters();
   if (params != null && params.length > 0) {
     String tmp = null;
     if (params[0] instanceof Class<?>) tmp = ((Class<?>) params[0]).getSimpleName();
     else if (params[0] != null) tmp = params[0].getClass().getSimpleName();
     if (tmp != null) method_name = method_name + "-" + tmp;
   }
   return method_name;
 }
コード例 #6
0
 private void printTestResults(ITestResult result) {
   Reporter.log("TestName = " + method, true);
   Reporter.log("Test Method resides in " + result.getTestClass().getName(), true);
   if (result.getParameters().length != 0) {
     String params = null;
     for (Object parameter : result.getParameters()) {
       params += parameter.toString() + ",";
     }
     Reporter.log("Test Method had the following parameters : " + params, true);
   }
   String status = null;
   switch (result.getStatus()) {
     case ITestResult.SUCCESS:
       status = "Pass";
       break;
     case ITestResult.FAILURE:
       status = "Failed";
       break;
     case ITestResult.SKIP:
       status = "Skipped";
   }
   Reporter.log("Test Status: " + status, true);
 }
コード例 #7
0
  public static List<String> getPageListenerLogByMethodInstance(final ITestResult testResult) {

    for (Entry<String, Map<String, Map<String, List<String>>>> listenerEntry : logMap.entrySet()) {
      if (!PluginsHelper.getInstance().isTestResultEffected(listenerEntry.getKey())) {
        continue;
      }

      Map<String, Map<String, List<String>>> pageMap = listenerEntry.getValue();
      for (Entry<String, Map<String, List<String>>> pageEntry : pageMap.entrySet()) {
        Map<String, List<String>> errorMap = pageEntry.getValue();
        String methodInstance =
            StringUtility.constructMethodSignature(
                testResult.getMethod().getConstructorOrMethod().getMethod(),
                testResult.getParameters());
        return errorMap.get(methodInstance);
      }
    }

    return null;
  }
コード例 #8
0
ファイル: TestReporter.java プロジェクト: wasche/jacss
 @Override
 public void onTestFailure(ITestResult testResult) {
   @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
   Throwable throwable = testResult.getThrowable();
   if (throwable instanceof AssertionError) {
     Matcher m = ASSERT_EQ_PATTERN.matcher(throwable.getMessage());
     if (m.matches()) {
       String test = m.group(1);
       String expected = m.group(2).replaceAll("\n", "\\\\n");
       String actual = m.group(3).replaceAll("\n", "\\\\n");
       System.out.println(test);
       System.out.println("- " + expected);
       System.out.println("+ " + actual);
     } else {
       System.out.println("failed: " + throwable.getMessage());
     }
   } else {
     System.out.println(
         throwable.getClass().getSimpleName() + ": " + testResult.getParameters()[0]);
   }
 }
コード例 #9
0
 // returns an ID for each test result
 private int getTestId(ITestResult result) {
   int id = result.getTestClass().getName().hashCode();
   id = 31 * id + result.getMethod().getMethodName().hashCode();
   id = 31 * id + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0);
   return id;
 }
コード例 #10
0
  /** @param tests */
  private void resultSummary(
      ISuite suite, IResultMap tests, String testname, String style, String details) {
    if (tests.getAllResults().size() > 0) {
      StringBuffer buff = new StringBuffer();
      String lastClassName = "";
      int mq = 0;
      int cq = 0;
      Map<String, Integer> methods = new HashMap<String, Integer>();
      Set<String> setMethods = new HashSet<String>();
      for (ITestNGMethod method : getMethodSet(tests, suite)) {
        m_row += 1;

        ITestClass testClass = method.getTestClass();
        String className = testClass.getName();
        if (mq == 0) {
          String id = (m_testIndex == null ? null : "t" + Integer.toString(m_testIndex));
          titleRow(testname + " &#8212; " + style + details, 5, id);
          m_testIndex = null;
        }
        if (!className.equalsIgnoreCase(lastClassName)) {
          if (mq > 0) {
            cq += 1;
            m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
            if (mq > 1) {
              m_out.print(" rowspan=\"" + mq + "\"");
            }
            m_out.println(">" + lastClassName + "</td>" + buff);
          }
          mq = 0;
          buff.setLength(0);
          lastClassName = className;
        }
        Set<ITestResult> resultSet = tests.getResults(method);
        long end = Long.MIN_VALUE;
        long start = Long.MAX_VALUE;
        for (ITestResult testResult : tests.getResults(method)) {
          if (testResult.getEndMillis() > end) {
            end = testResult.getEndMillis();
          }
          if (testResult.getStartMillis() < start) {
            start = testResult.getStartMillis();
          }
        }
        mq += 1;
        if (mq > 1) {
          buff.append("<tr class=\"" + style + (cq % 2 == 0 ? "odd" : "even") + "\">");
        }
        String description = method.getDescription();
        String testInstanceName = resultSet.toArray(new ITestResult[] {})[0].getTestName();
        // Calculate each test run times, the result shown in the html
        // report.
        ITestResult[] results = resultSet.toArray(new ITestResult[] {});
        String methodName = method.getMethodName();
        if (setMethods.contains(methodName)) {
          methods.put(methodName, methods.get(methodName) + 1);
        } else {
          setMethods.add(methodName);
          methods.put(methodName, 0);
        }
        String parameterString = "";
        int count = 0;

        ITestResult result = null;
        if (results.length > methods.get(methodName)) {
          result = results[methods.get(methodName)];
          int testId = getId(result);

          for (Integer id : allRunTestIds) {
            if (id.intValue() == testId) count++;
          }
          Object[] parameters = result.getParameters();

          boolean hasParameters = parameters != null && parameters.length > 0;
          if (hasParameters) {
            for (Object p : parameters) {
              parameterString = parameterString + Utils.escapeHtml(p.toString()) + " ";
            }
          }
        }

        int methodId = method.getTestClass().getName().hashCode();
        methodId = methodId + method.getMethodName().hashCode();
        if (result != null)
          methodId =
              methodId
                  + (result.getParameters() != null ? Arrays.hashCode(result.getParameters()) : 0);

        buff.append(
            "<td><a href=\"#m"
                + methodId
                + "\">"
                + qualifiedName(method)
                + " "
                + (description != null && description.length() > 0
                    ? "(\"" + description + "\")"
                    : "")
                + "</a>"
                + (null == testInstanceName ? "" : "<br>(" + testInstanceName + ")")
                + "</td><td>"
                + this.getAuthors(className, method)
                + "</td><td class=\"numi\">"
                + resultSet.size()
                + "</td>"
                + "<td>"
                + (count == 0 ? "" : count)
                + "</td>"
                + "<td>"
                + parameterString
                + "</td>"
                + "<td>"
                + start
                + "</td>"
                + "<td class=\"numi\">"
                + (end - start)
                + "</td>"
                + "</tr>");
      }
      if (mq > 0) {
        cq += 1;
        m_out.print("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td");
        if (mq > 1) {
          m_out.print(" rowspan=\"" + mq + "\"");
        }
        m_out.println(">" + lastClassName + "</td>" + buff);
      }
    }
  }