@Override public boolean isDefault(String s) { return Utils.isStringEmpty(s); } };
/** * Print out test summary */ private void logResults() { // // Log test summary // ITestNGMethod[] ft = resultsToMethods(getFailedTests()); StringBuilder sb = new StringBuilder("\n===============================================\n"); sb.append(" ").append(suiteName).append("\n"); sb.append(" Tests run: ").append(Utils.calculateInvokedMethodCount(getAllTestMethods())); sb.append(", Failures: ").append(Utils.calculateInvokedMethodCount(ft)); sb.append(", Skips: ").append(Utils.calculateInvokedMethodCount(resultsToMethods(getSkippedTests()))); int confFailures = getConfigurationFailures().size(); int confSkips = getConfigurationSkips().size(); if (confFailures > 0 || confSkips > 0) { sb.append("\n").append(" Configuration Failures: ").append(confFailures); sb.append(", Skips: ").append(confSkips); } sb.append("\n==============================================="); log(sb.toString()); }
msg.append(", "); msg.append(Utils.toString(params[i], paramTypes[i])); if (!Utils.isStringEmpty(description)) { msg.append("\n"); for (int i = 0; i < status.length() + 2; i++) { if (!Utils.isStringEmpty(stackTrace)) { msg.append("\n").append(stackTrace);
/** * @return an array of two strings: the short stack trace and the long stack trace. * @deprecated - Please consider using : * <ul> * <li>{@link Utils#longStackTrace(Throwable, boolean)} - for getting full stack trace</li> * <li>{@link Utils#shortStackTrace(Throwable, boolean)} - for getting short stack trace</li> * </ul> */ @Deprecated public static String[] stackTrace(Throwable t, boolean toHtml) { return new String[] { shortStackTrace(t, toHtml), longStackTrace(t, toHtml) }; }
/** * Writes the content of the sb string to the file named filename in outDir encoding the output as UTF-8. * If outDir does not exist, it is created. * * @param outputDir the output directory (may not exist). If <tt>null</tt> then current directory is used. * @param fileName the filename * @param sb the file content */ public static void writeUtf8File(@Nullable String outputDir, String fileName, String sb) { final String outDirPath= outputDir != null ? outputDir : ""; final File outDir= new File(outDirPath); writeFile(outDir, fileName, escapeUnicode(sb), "UTF-8"); }
private static String buildStackTrace(Throwable t, boolean toHtml, StackTraceType type) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); pw.flush(); String stackTrace = sw.getBuffer().toString(); if (type == StackTraceType.SHORT && !isTooVerbose()) { stackTrace = filterTrace(sw.getBuffer().toString()); } if (toHtml) { stackTrace = escapeHtml(stackTrace); } return stackTrace; }
sb.append("SKIPPED"); stackTrace = itr.getThrowable() != null ? Utils.stackTrace(itr.getThrowable(), false)[0] : ""; break; case FAILURE: sb.append("FAILED"); stackTrace = itr.getThrowable() != null ? Utils.stackTrace(itr.getThrowable(), false)[0] : ""; break; case SUCCESS: sb.append(", "); sb.append(Utils.toString(params[i], paramTypes[i])); sb.append(itr.getEndMillis() - itr.getStartMillis()); sb.append(" ms"); if (!Utils.isStringEmpty(tm.getDescription())) { sb.append("\n"); for (int i = 0; i < identLevel; i++) { sb.append(")"); if (!Utils.isStringEmpty(stackTrace)) { sb.append("\n").append(stackTrace.substring(0, stackTrace.lastIndexOf(System.getProperty("line.separator"))));
sb.append("SKIPPED"); stackTrace = itr.getThrowable() != null ? Utils.shortStackTrace(itr.getThrowable(), false) : ""; break; case FAILURE: sb.append("FAILED"); stackTrace = itr.getThrowable() != null ? Utils.shortStackTrace(itr.getThrowable(), false) : ""; break; case SUCCESS: sb.append(", "); sb.append(Utils.toString(params[i], paramTypes[i])); sb.append(itr.getEndMillis() - itr.getStartMillis()); sb.append(" ms"); if (!Utils.isStringEmpty(tm.getDescription())) { sb.append("\n"); for (int i = 0; i < identLevel; i++) { sb.append(")"); if (!Utils.isStringEmpty(stackTrace)) { sb.append("\n").append(stackTrace.substring(0, stackTrace.lastIndexOf(System.getProperty("line.separator"))));
private void createExceptionProperty(Throwable thrown, Resource resource) { if (thrown.getClass().getName().contains(SKIP)) resource.addProperty(DCTerms.description, thrown.getMessage()); else resource.addLiteral(DCTerms.description, Utils.stackTrace(thrown, false)[0]); }
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(); } XMLReporterConfig.StackTraceLevels level = calculateStackTraceLevels(testResult); switch (level) { case SHORT: xmlBuffer.push(XMLReporterConfig.TAG_SHORT_STACKTRACE); xmlBuffer.addCDATA(Utils.shortStackTrace(exception, false)); xmlBuffer.pop(); break; case FULL: xmlBuffer.push(XMLReporterConfig.TAG_FULL_STACKTRACE); xmlBuffer.addCDATA(Utils.longStackTrace(exception, false)); xmlBuffer.pop(); break; default: //everything else is ignored for now. } xmlBuffer.pop(); } }
private void writeSuiteToFile(File suiteFile, ISuite suite) { XMLStringBuffer xmlBuffer = new XMLStringBuffer(); writeSuiteToBuffer(xmlBuffer, suite); File parentDir = suiteFile.getParentFile(); suiteFile.getParentFile().mkdirs(); if (parentDir.exists() || suiteFile.getParentFile().exists()) { Utils.writeUtf8File(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML()); } }
@Override public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) { if (Utils.isStringEmpty(config.getOutputDirectory())) { config.setOutputDirectory(outputDirectory); Utils.writeUtf8File(config.getOutputDirectory(), fileName(), rootBuffer, null /* no prefix */);
private boolean dumpParametersInfo(String prefix, Object[] parameters) { int parameterCount = (parameters == null ? 0 : parameters.length); if (parameterCount == 0) { return false; } writer.print("<tr class=\"param\">"); for (int i = 1; i <= parameterCount; i++) { writer.print(String.format("<th>%s #", prefix)); writer.print(i); writer.print("</th>"); } writer.print("</tr><tr class=\"param stripe\">"); for (Object parameter : parameters) { writer.print("<td>"); writer.print(Utils.escapeHtml(Utils.toString(parameter))); writer.print("</td>"); } writer.print("</tr>"); return true; }
String stackTrace = ""; if (ex != null && m_verbose >= 2) { stackTrace = Utils.shortStackTrace(ex, false); Utils.detailedMethodName(tr.getMethod(), false), tr.getMethod().getDescription(), stackTrace, Utils.detailedMethodName(tr.getMethod(), false), tr.getMethod().getDescription(), null, String stackTrace= ""; if (ex != null && m_verbose >= 2) { stackTrace= Utils.shortStackTrace(ex, false); logResult("SKIPPED", tr, throwable != null ? Utils.shortStackTrace(throwable, false) : null); StringBuilder logBuf = new StringBuilder("\n===============================================\n"); logBuf.append(" ").append(m_testName).append("\n"); logBuf.append(" Tests run: ").append(Utils.calculateInvokedMethodCount(getAllTestMethods())) .append(", Failures: ").append(Utils.calculateInvokedMethodCount(ft)) .append(", Skips: ").append(Utils.calculateInvokedMethodCount(resultsToMethods(getSkippedTests()))); int confFailures = getConfigurationFailures().size(); int confSkips = getConfigurationSkips().size();
suites.append(s); Utils.log("TestNG", 2, "Ignoring the XML file inside " + m_jarPath + " and using " + suites + " instead"); return; if (isStringEmpty(m_jarPath)) { return;
protected void writeReporterMessages(List<String> reporterMessages) { writer.print("<div class=\"messages\">"); Iterator<String> iterator = reporterMessages.iterator(); assert iterator.hasNext(); if (Reporter.getEscapeHtml()) { writer.print(Utils.escapeHtml(iterator.next())); } else { writer.print(iterator.next()); } while (iterator.hasNext()) { writer.print("<br/>"); if (Reporter.getEscapeHtml()) { writer.print(Utils.escapeHtml(iterator.next())); } else { writer.print(iterator.next()); } } writer.print("</div>"); }
if (!first) sb.append(", "); first = false; sb.append(Utils.toString(p)); stackTrace.append(Utils.shortStackTrace(tr.getThrowable(), true)); xsb.addOptional(D, stackTrace.toString() + "\n", C, "stack-trace");
private void addArgumentsIfNotEmpty(List<String> argv, String name, List<String> arguments, String separator) { if (arguments != null && !arguments.isEmpty()) { argv.add(name); String value= Utils.join(arguments, separator); argv.add(value); } }
public static void checkReturnType(Method method, Class<?>... returnTypes) { if (method == null) { return; } for (Class<?> returnType : returnTypes) { if (method.getReturnType() == returnType) { return; } } throw new TestNGException(method.getDeclaringClass().getName() + "." + method.getName() + " MUST return " + toString(returnTypes) + " but returns " + method.getReturnType().getName()); }
protected void writeStackTrace(Throwable throwable) { writer.print("<div class=\"stacktrace\">"); writer.print(Utils.shortStackTrace(throwable, true)); writer.print("</div>"); }