本文整理了Java中org.testng.internal.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:org.testng.internal.Utils
类名称:Utils
[英]Helper methods to parse annotations.
[中]解析注释的助手方法。
代码示例来源:origin: org.testng/testng
@Override
public boolean isDefault(String s) {
return Utils.isStringEmpty(s);
}
};
代码示例来源:origin: org.testng/testng
/**
* 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());
}
代码示例来源:origin: org.testng/testng
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);
代码示例来源:origin: org.testng/testng
/**
* @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)
};
}
代码示例来源:origin: org.testng/testng
/**
* 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");
}
代码示例来源:origin: org.testng/testng
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;
}
代码示例来源:origin: io.brooklyn/brooklyn-utils-test-support
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"))));
代码示例来源:origin: org.testng/testng
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"))));
代码示例来源:origin: org.w3/ldp-testsuite
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]);
}
代码示例来源:origin: org.testng/testng
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();
}
}
代码示例来源:origin: org.testng/testng
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());
}
}
代码示例来源:origin: org.testng/testng
@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 */);
代码示例来源:origin: cbeust/testng
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;
}
代码示例来源:origin: org.testng/testng
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();
代码示例来源:origin: org.testng/testng
suites.append(s);
Utils.log("TestNG", 2, "Ignoring the XML file inside " + m_jarPath + " and using "
+ suites + " instead");
return;
if (isStringEmpty(m_jarPath)) {
return;
代码示例来源:origin: org.testng/testng
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>");
}
代码示例来源:origin: org.testng/testng
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");
代码示例来源:origin: org.testng/testng
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);
}
}
代码示例来源:origin: org.testng/testng
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());
}
代码示例来源:origin: org.testng/testng
protected void writeStackTrace(Throwable throwable) {
writer.print("<div class=\"stacktrace\">");
writer.print(Utils.shortStackTrace(throwable, true));
writer.print("</div>");
}
内容来源于网络,如有侵权,请联系作者删除!