Java 类org.testng.internal.Utils 实例源码

项目:DolphinNG    文件:EmailableReporter.java   
private void generateExceptionReport(Throwable exception, ITestNGMethod method, String title)
{
    m_out.println("<p>" + Utils.escapeHtml(title) + "</p>");
    StackTraceElement[] s1 = exception.getStackTrace();
    Throwable t2 = exception.getCause();
    if (t2 == exception)
    {
        t2 = null;
    }
    int maxlines = Math.min(100, StackTraceTools.getTestRoot(s1, method));
    for (int x = 0; x <= maxlines; x++)
    {
        m_out.println((x > 0 ? "<br/>at " : "") + Utils.escapeHtml(s1[x].toString()));
    }
    if (maxlines < s1.length)
    {
        m_out.println("<br/>" + (s1.length - maxlines) + " lines not shown");
    }
    if (t2 != null)
    {
        generateExceptionReport(t2, method, "Caused by " + t2.getLocalizedMessage());
    }
}
项目:heat    文件:CustomJUnitReportListener.java   
private void setFailedTcAttribute(XMLStringBuffer doc, ITestResult failedTestCase) {
    Properties attributesFailedTestSuites = new Properties();
    String tcName = ((HashMap<String, String>) failedTestCase.getParameters()[0]).get(PROP_TEST_ID);
    attributesFailedTestSuites.setProperty(XMLConstants.ATTR_NAME, tcName);
    long elapsedTimeMillis = failedTestCase.getEndMillis() - failedTestCase.getStartMillis();
    testRunningTotalTime += elapsedTimeMillis;
    Throwable t = failedTestCase.getThrowable();
    doc.push(XMLConstants.TESTCASE, attributesFailedTestSuites);
    if (t != null) {
        attributesFailedTestSuites.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
        String message = t.getMessage();
        if ((message != null) && (message.length() > 0)) {
            attributesFailedTestSuites.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
        }
        doc.push(XMLConstants.FAILURE, attributesFailedTestSuites);
        doc.addCDATA(Utils.stackTrace(t, false)[0]);
        doc.pop();
    } else {
        doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
    }
    doc.pop();
}
项目:wtf-core    文件:XmlJuintReport.java   
public static void createFailureElement(XMLStringBuffer doc, ITestResult tr) {
  Properties attrs = new Properties();
  Throwable t = tr.getThrowable();
  if (t != null) {
    attrs.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
    String message= t.getMessage();
    if ((message != null) && (message.length() > 0)) {
      attrs.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
    }
    doc.push(XMLConstants.FAILURE, attrs);
    doc.addCDATA(Utils.stackTrace(t, false)[0]);
    doc.pop();
  } else {
    doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
  }
}
项目:wtf-core    文件:BaseTestRetryAnalyzer.java   
/**
 * Print the test status while test retry.
 */
public boolean retry(ITestResult result) {
  Throwable throwable = result.getThrowable();

  String testClassName = String.format("%s.%s",
      result.getMethod().getRealClass().toString(), result.getMethod().getMethodName()).
          replace("class com.ebay.webdriver.", "..");

  if (throwable != null) {
    LOG(Level.SEVERE,
        "STACK TRACE: " + testClassName + "\n" + Utils.stackTrace(throwable, false)[0]);
  }

  if(count <= maxCount) {
    result.setAttribute("RETRY", new Integer(count));

    LOG(Level.WARNING, "[RETRYING] " + testClassName + " FAILED, " +
        "Retrying " + count + " times");

    count += 1;
    return true;
  }
  return false;
}
项目:automation-test-engine    文件:GenericATEProblem.java   
/**
 * Instantiates a new generic ate problem.
 *
 * @param source
 *            the source
 * @param see
 *            the see
 */
public GenericATEProblem(Object source, Exception exception) {
    super(source, exception);
    String[] stackTraces = Utils.stackTrace(exception, false);
    String tmp1 = stackTraces[1];
    if (tmp1 == null)
        fullStackTrace = "fullstacktrace Internal error.";

    else
        fullStackTrace = tmp1;
    String tmp0 = stackTraces[0];
    if (tmp0 == null)
        shortStackTrace = "shortstacktrace Internal error.";
    else
        shortStackTrace = tmp0;
    final Level warn2 = Level.WARN;
    if (warn2 == null) {
        throw GlobalUtils.createInternalError("jvm");
    } else {
        this.loggingLevel = warn2;
    }
    if (exception instanceof IATEException) this.ateException = (IATEException) exception;
    this.fatalProblem = true;
    this.problemMessage = exception.getMessage();
}
项目:automation-test-engine    文件:GenericATEProblem.java   
/**
 * Instantiates a new generic ate problem.
 *
 * @param source
 *            the source
 * @param exception
 *            the exception
 */
public GenericATEProblem(Object source, Throwable exception) {
    super(source, exception);
    String[] stackTraces = Utils.stackTrace(exception, false);
    String tmp1 = stackTraces[1];
    if (tmp1 == null)
        fullStackTrace = "fullstacktrace Internal error.";

    else
        fullStackTrace = tmp1;
    String tmp0 = stackTraces[0];
    if (tmp0 == null)
        shortStackTrace = "shortstacktrace Internal error.";
    else
        shortStackTrace = tmp0;
    final Level warn2 = Level.WARN;
    if (warn2 == null) {
        throw GlobalUtils.createInternalError("jvm");
    } else {
        this.loggingLevel = warn2;
    }
    this.fatalProblem = false;
    if (exception instanceof IATEException) this.ateException = (IATEException) exception;
    this.problemMessage = exception.getMessage();
}
项目:oldmonk    文件:ReporterAPI.java   
private String generateExceptionReport(Throwable exception, ITestNGMethod method, String title)
{
    StackTraceElement[] s1 = exception.getStackTrace();
    Throwable t2 = exception.getCause();

    StringBuilder exceptionStackTrace = new StringBuilder();

    if (t2 == exception)
    {
        t2 = null;
    }
    int maxlines = Math.min(100, StackTraceTools.getTestRoot(s1, method));
    for (int x = 0; x <= maxlines; x++)
    {
        exceptionStackTrace.append((x > 0 ? "<br/>at " : "") + Utils.escapeHtml(s1[x].toString()));
    }
    if (maxlines < s1.length)
    {
        exceptionStackTrace.append("<br/>" + (s1.length - maxlines) + " lines not shown");
    }
    if (t2 != null)
    {
        generateExceptionReport(t2, method, "Caused by " + t2.getLocalizedMessage());
    }

    return exceptionStackTrace.toString();
}
项目:wtf-core    文件:SoftAssert.java   
public void flushSoftAsserts() {
  LOG(Level.INFO, String.format("Found Soft Asserts(%s)", count()));
  for (Throwable throwable : softAssertList) {
    if (throwable != null) {
      LOG(Level.SEVERE, Utils.stackTrace(throwable, false)[0]);
    }
  }
  LOG(Level.INFO, "End of Soft Asserts..");
}
项目:wtf-core    文件:XmlJuintReport.java   
public static void createElement(XMLStringBuffer doc, ITestResult tr) {
  Properties attrs = new Properties();
  long elapsedTimeMillis = tr.getEndMillis() - tr.getStartMillis();
  String name =
      tr.getMethod().isTest() ? tr.getName() : Utils.detailedMethodName(tr.getMethod(), false);

  //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMMMM hh:mm aaa");
  //String testRunTest = String.format("%s", simpleDateFormat.format(new Date()));

  String testRunTest = FastDateFormat.getInstance("dd-MMMMM hh:mm aaa").format(new Date());

  attrs.setProperty(XMLConstants.ATTR_NAME, String.format("%s  [%s]", name, testRunTest));
  attrs.setProperty(XMLConstants.ATTR_CLASSNAME, tr.getTestClass().getRealClass().getName());
  attrs.setProperty(XMLConstants.ATTR_TIME, "" + (((double) elapsedTimeMillis) / 1000));

  if((ITestResult.FAILURE == tr.getStatus()) || (ITestResult.SKIP == tr.getStatus())) {
    doc.push(XMLConstants.TESTCASE, attrs);

    if(ITestResult.FAILURE == tr.getStatus()) {
      createFailureElement(doc, tr);
    }
    else if(ITestResult.SKIP == tr.getStatus()) {
      createSkipElement(doc, tr);
    }
    doc.pop();
  }else {
    doc.addEmptyElement(XMLConstants.TESTCASE, attrs);
  }
}
项目:wtf-core    文件:BaseListener.java   
public static String getDetailedStackTrace(ITestResult tr) {
  String failureTrace = "";
  Throwable throwable = tr.getThrowable();
  if (throwable != null) {
    failureTrace = Utils.stackTrace(throwable, false)[0];
  } else {
    failureTrace = "No Stack Trace Found.";
  }
  return failureTrace;
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
        String outputDirectory) {
    if (Utils.isStringEmpty(config.getOutputDirectory())) {
        config.setOutputDirectory(outputDirectory);
    }

    // Calculate passed/failed/skipped
    int passed = 0;
    int failed = 0;
    int skipped = 0;
    for (ISuite s : suites) {
        for (ISuiteResult sr : s.getResults().values()) {
            ITestContext testContext = sr.getTestContext();
            passed += testContext.getPassedTests().size();
            failed += testContext.getFailedTests().size();
            skipped += testContext.getSkippedTests().size();
        }
    }

    rootBuffer = new XMLStringBuffer();
    Properties p = new Properties();
    p.put("passed", passed);
    p.put("failed", failed);
    p.put("skipped", skipped);
    p.put("total", passed + failed + skipped);
    rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);
    writeReporterOutput(rootBuffer);
    for (int i = 0; i < suites.size(); i++) {
        writeSuite(suites.get(i).getXmlSuite(), suites.get(i));
    }
    rootBuffer.pop();
    Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer,
            null /* no prefix */);
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
private void writeSuiteToFile(File suiteFile, ISuite suite) {
    XMLStringBuffer xmlBuffer = new XMLStringBuffer();
    writeSuiteToBuffer(xmlBuffer, suite);
    File parentDir = suiteFile.getParentFile();
    if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {
        Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME,
                xmlBuffer.toXML());
    }
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
/**
* Writes the specified ISuiteResult in the given XMLStringBuffer. Please consider that depending on the settings in
* the <code>config</code> property it might generate an additional XML file with the actual content and only
* reference the file with an <code>url</code> attribute in the passed XMLStringBuffer.
*
* @param xmlBuffer The XML buffer where to write or reference the suite result
* @param suiteResult The <code>ISuiteResult</code> to serialize
*/
  public void writeSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {
    if (XMLReporterConfig.FF_LEVEL_SUITE_RESULT != config.getFileFragmentationLevel()) {
      writeAllToBuffer(xmlBuffer, suiteResult);
    } else {
      String parentDir =
              config.getOutputDirectory() + File.separatorChar + suiteResult.getTestContext().getSuite().getName();
      File file = referenceSuiteResult(xmlBuffer, parentDir, suiteResult);
      XMLStringBuffer suiteXmlBuffer = new XMLStringBuffer();
      writeAllToBuffer(suiteXmlBuffer, suiteResult);
      Utils.writeUtf8File(file.getAbsoluteFile().getParent(), file.getName(), suiteXmlBuffer.toXML());
    }
  }
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResultException(XMLStringBuffer xmlBuffer, ITestResult testResult) {
  Throwable exception = testResult.getThrowable();
  if (exception != null) {
    Properties exceptionAttrs = new Properties();
    exceptionAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, exception.getClass().getName());
    xmlBuffer.push(XMLReporterConfig.TAG_EXCEPTION, exceptionAttrs);

    if (!Utils.isStringEmpty(exception.getMessage())) {
      xmlBuffer.push(XMLReporterConfig.TAG_MESSAGE);
      xmlBuffer.addCDATA(exception.getMessage());
      xmlBuffer.pop();
    }

    String[] stackTraces = Utils.stackTrace(exception, false);
    if ((config.getStackTraceOutputMethod() & XMLReporterConfig.STACKTRACE_SHORT) == XMLReporterConfig
            .STACKTRACE_SHORT) {
      xmlBuffer.push(XMLReporterConfig.TAG_SHORT_STACKTRACE);
      xmlBuffer.addCDATA(stackTraces[0]);
      xmlBuffer.pop();
    }
    if ((config.getStackTraceOutputMethod() & XMLReporterConfig.STACKTRACE_FULL) == XMLReporterConfig
            .STACKTRACE_FULL) {
      xmlBuffer.push(XMLReporterConfig.TAG_FULL_STACKTRACE);
      xmlBuffer.addCDATA(stackTraces[1]);
      xmlBuffer.pop();
    }

    xmlBuffer.pop();
  }
}
项目:harness    文件:TestReporter.java   
private void generateExceptionReport(Throwable exception,ITestNGMethod method,String title) {
    out.println("<p>" + (title != null && title.startsWith("Failed")?"java.lang.AssertionError : ":"") + Utils.escapeHtml(title) + "</p>");
    StackTraceElement[] s1= exception.getStackTrace();
    Throwable t2= exception.getCause();
    if(t2 == exception)
        t2= null;
    for(int i=0;i<s1.length;i++)
        out.println((i>0 ? "<br/>at " : "") + Utils.escapeHtml(s1[i].toString()));
    if(t2 != null)
        generateExceptionReport(t2, method, "Caused by " + t2.getLocalizedMessage());
}
项目:WebAndAppUITesting    文件:PowerEmailableReporter.java   
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>");
    }
}
项目:WebAndAppUITesting    文件:PowerEmailableReporter.java   
protected void generateExceptionReport(Throwable exception, ITestNGMethod method) {
    m_out.print("<div class=\"stacktrace\">");
    m_out.print(Utils.stackTrace(exception, true)[0]);
    m_out.println("</div>");
}
项目:qaf    文件:TestClass.java   
private void log(int level, String s) {
  Utils.log("TestClass", level, s);
}
项目:qaf    文件:TestRunner.java   
/**
 * Main method that create a graph of methods and then pass it to the
 * graph executor to run them.
 */
private void privateRun(XmlTest xmlTest) {
  boolean parallel = xmlTest.getParallel().isParallel();

  {
    // parallel
    int threadCount = parallel ? xmlTest.getThreadCount() : 1;
    // Make sure we create a graph based on the intercepted methods, otherwise an interceptor
    // removing methods would cause the graph never to terminate (because it would expect
    // termination from methods that never get invoked).
    DynamicGraph<ITestNGMethod> graph = createDynamicGraph(intercept(m_allTestMethods));
    if (parallel) {
      if (graph.getNodeCount() > 0) {
        GraphThreadPoolExecutor<ITestNGMethod> executor =
                new GraphThreadPoolExecutor<ITestNGMethod>(graph, this,
                        threadCount, threadCount, 0, TimeUnit.MILLISECONDS,
                        new LinkedBlockingQueue<Runnable>());
        executor.run();
        try {
          long timeOut = m_xmlTest.getTimeOut(XmlTest.DEFAULT_TIMEOUT_MS);
          Utils.log("TestRunner", 2, "Starting executor for test " + m_xmlTest.getName()
              + " with time out:" + timeOut + " milliseconds.");
          executor.awaitTermination(timeOut, TimeUnit.MILLISECONDS);
          executor.shutdownNow();
        } catch (InterruptedException handled) {
          handled.printStackTrace();
          Thread.currentThread().interrupt();
        }
      }
    } else {
      boolean debug = false;
      List<ITestNGMethod> freeNodes = graph.getFreeNodes();
      if (debug) {
        System.out.println("Free nodes:" + freeNodes);
      }

      if (graph.getNodeCount() > 0 && freeNodes.isEmpty()) {
        throw new TestNGException("No free nodes found in:" + graph);
      }

      while (! freeNodes.isEmpty()) {
        List<IWorker<ITestNGMethod>> runnables = createWorkers(freeNodes);
        for (IWorker<ITestNGMethod> r : runnables) {
          r.run();
        }
        graph.setStatus(freeNodes, Status.FINISHED);
        freeNodes = graph.getFreeNodes();
        if (debug) {
          System.out.println("Free nodes:" + freeNodes);
        }
      }
    }
  }
}
项目:qaf    文件:TestRunner.java   
private void log(int level, String s) {
  Utils.log("TestRunner", level, s);
}
项目:qaf    文件:TestRunner.java   
private void log(String s) {
  Utils.log("TestRunner", 2, s);
}
项目:webUIAuto    文件:PowerEmailableReporter.java   
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>");
    }
}
项目:webUIAuto    文件:PowerEmailableReporter.java   
protected void generateExceptionReport(Throwable exception, ITestNGMethod method) {
    m_out.print("<div class=\"stacktrace\">");
    m_out.print(Utils.stackTrace(exception, true)[0]);
    m_out.println("</div>");
}
项目:seleniumtestsframework    文件:SeleniumTestsReporter.java   
public void afterInvocation(final IInvokedMethod method, final ITestResult result) {
    Reporter.setCurrentTestResult(result);

    // Handle Soft CustomAssertion
    if (method.isTestMethod()) {
        final List<Throwable> verificationFailures = CustomAssertion.getVerificationFailures();

        final int size = verificationFailures.size();
        if (size == 0) {
            return;
        } else if (result.getStatus() == TestResult.FAILURE) {
            return;
        }

        result.setStatus(TestResult.FAILURE);

        if (size == 1) {
            result.setThrowable(verificationFailures.get(0));
        } else {

            // create failure message with all failures and stack traces barring last failure)
            final StringBuilder failureMessage = new StringBuilder("!!! Many Test Failures (").append(size).append(
                    ")\n");
            for (int i = 0; i < size - 1; i++) {
                failureMessage.append("Failure ").append(i + 1).append(" of ").append(size).append("\n");

                final Throwable t = verificationFailures.get(i);
                final String fullStackTrace = Utils.stackTrace(t, false)[1];
                failureMessage.append(fullStackTrace).append("\n");
            }

            // final failure
            final Throwable last = verificationFailures.get(size - 1);
            failureMessage.append("Failure ").append(size).append(" of ").append(size).append(":n");
            failureMessage.append(last.toString());

            // set merged throwable
            final Throwable merged = new Throwable(failureMessage.toString());
            merged.setStackTrace(last.getStackTrace());

            result.setThrowable(merged);
        }
    }
}
项目:automation-test-engine    文件:CaseRunner.java   
/**
     * Test runner1.
     * 
     * @param ctx
     *            the ctx
     * @throws Throwable
     */
    // @Test(dataProvider = "dp")
    public void runTest(TestParameters testParams) throws Throwable {
        String testname = testParams.getTestFilename();

        // ApplicationContext context;
        try {
            context = new FileSystemXmlApplicationContext(testname);
            IMyWebDriver myWebD = (IMyWebDriver) GlobalUtils
                    .findMyWebDriver(context);
            mainDriver = myWebD.getWebDriverInstance();
            myTestCase = GlobalUtils.findTestCaseBean(getContext());
            getMyTestCase().setStepThinkTime(testParams.getStepThinkTime());
            getMyTestCase().setCurrentWebDriver(myWebD);
            getMyTestCase().setParentTestProject(testParams.getTestProject());
            getMyTestCase().goSteps();

        } catch (FatalBeanException fbe) {
            if (fbe.getCause() instanceof FileNotFoundException) {
                context = new ClassPathXmlApplicationContext(testname);
                mainDriver = ((IMyWebDriver) GlobalUtils
                        .findMyWebDriver(context)).getWebDriverInstance();
                myTestCase = GlobalUtils.findTestCaseBean(getContext());
                myTestCase.setStepThinkTime(testParams.getStepThinkTime());
                getMyTestCase().goSteps();

            } else if (fbe instanceof BeanCreationException) { // NOPMD
                ITestResult itr = Reporter.getCurrentTestResult();

                if (itr.getThrowable() != null
                        && itr.getThrowable() instanceof TestDataException) {
                    TestDataException tde = (TestDataException) itr
                            .getThrowable();
                    tde.setTestStepName(((BeanCreationException) fbe.getCause())
                            .getBeanName());
                    tde.setTestCaseName(((BeanCreationException) fbe)
                            .getResourceDescription());
                    tde.setMessage(tde.getMessage() + LogbackTag.TAG_SEPERATOR
                            + tde.getTestCaseName() + LogbackTag.TAG_SEPERATOR
                            + tde.getTestStepName());
                    throw (TestDataException) itr.getThrowable();
                } else { // other test case bean creation errors. need to create
                    // another exception to handle it.
                    String[] fullST = Utils.stackTrace(fbe, false);
                    int TWO = 2; // NOPMD
                    if (fullST.length < TWO) {
                        LogbackWriter
                                .writeSysError("java internal error in stack trace.");
                    } else {
                        String errLog = fullST[1];
                        if (null == errLog)
                            LogbackWriter
                                    .writeSysError("java internal error in stack trace.");
                        else
                            LogbackWriter.writeSysError(errLog);
                    }
                    throw fbe;

                }
            } else {
                throw fbe;
            }
        }
//      catch (Throwable th) {//NOPMD
//          LogbackWriter.printStackTrace(th);
//          throw th;
//      }
    }
项目:harness    文件:TestReporter.java   
private void generateForResult(ITestResult ans, ITestNGMethod method, int resultSetSize) {
    int rq = 0;
    rq += 1;
    Object[] parameters = ans.getParameters();
    boolean hasParameters = parameters != null && parameters.length > 0;
    if (hasParameters) {
        if (rq == 1) {
            startTable(null, 0);
            out.print("<tr>");
            for (int x = 1; x <= parameters.length; x++) {
                out.print("<th>Parameter #"
                        + x + "</th>");
            }
            out.println("</tr>");
        }
        out.print("<tr>");
        for (Object p : parameters) {
            out.println("<td style='text-align:center'>"
                    + (p != null ? Utils.escapeHtml(p.toString()) : "null") + "</td>");
        }
        out.println("</tr>");
    }
    List<String> msgs = org.testng.Reporter.getOutput(ans);
    boolean hasReporterOutput = msgs.size() > 0;
    Throwable exception=ans.getThrowable();
    boolean hasThrowable = exception!=null;
    if (hasReporterOutput||hasThrowable) {
        String indent = " style=\"padding-left:3em\"";
        if (hasParameters)
            out.println("<tr><td colspan='"+ parameters.length+"'>");
        else
            out.println("<div>");
        if (hasReporterOutput) {
            if(hasThrowable)
                out.println("<h3>Test Messages</h3>");
            for (String line : msgs)
                out.println(line + "<br/>");
        }
        if(hasThrowable) {
            boolean wantsMinimalOutput = ans.getStatus()==ITestResult.SUCCESS;
            if(hasReporterOutput)
                out.println("<h3>" + (wantsMinimalOutput?"Expected Exception":"Failure") + "</h3>");
            generateExceptionReport(exception,method);
        }
        if (hasParameters)
            out.println("</td></tr>");
        else
            out.println("</div>");
    }
    if (hasParameters)
    {
        //if (rq == resultSetSize)
        out.println("</table>");
    }
}