Code with Finding: |
class VerboseReporter {
/**
* Log meaningful message for passed in arguments.
* Message itself is of form:
* $status: "$suiteName" - $methodDeclaration ($actualArguments) finished in $x ms ($run of $totalRuns)
*
* @param st status of passed in itr
* @param itr test result to be described
* @param isConfMethod is itr describing configuration method
*/
private void logTestResult(Status st, ITestResult itr, boolean isConfMethod) {
StringBuilder sb = new StringBuilder();
StringBuilder succRate = null;
String stackTrace = "";
switch (st) {
case STARTED:
sb.append("INVOKING");
break;
case SKIP:
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("PASSED");
break;
case SUCCESS_PERCENTAGE_FAILURE:
sb.append("PASSED with failures");
break;
default:
//not happen
throw new RuntimeException("Unsupported test status:" + itr.getStatus());
}
if (isConfMethod) {
sb.append(" CONFIGURATION: ");
} else {
sb.append(": ");
}
ITestNGMethod tm = itr.getMethod();
int identLevel = sb.length();
sb.append(getMethodDeclaration(tm));
Object[] params = itr.getParameters();
Class[] paramTypes = tm.getMethod().getParameterTypes();
if (null != params && params.length > 0) {
// The error might be a data provider parameter mismatch, so make
// a special case here
if (params.length != paramTypes.length) {
sb.append("Wrong number of arguments were passed by the Data Provider: found ");
sb.append(params.length);
sb.append(" but expected ");
sb.append(paramTypes.length);
} else {
sb.append("(value(s): ");
for (int i = 0; i < params.length; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(Utils.toString(params[i], paramTypes[i]));
}
sb.append(")");
}
}
if (Status.STARTED != st) {
sb.append(" finished in ");
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(" ");
}
sb.append(tm.getDescription());
}
if (tm.getInvocationCount() > 1) {
sb.append(" (");
sb.append(tm.getCurrentInvocationCount());
sb.append(" of ");
sb.append(tm.getInvocationCount());
sb.append(")");
}
if (!Utils.isStringEmpty(stackTrace)) {
sb.append("\n").append(stackTrace.substring(0, stackTrace.lastIndexOf(System.getProperty("line.separator"))));
}
} else {
if (!isConfMethod && tm.getInvocationCount() > 1) {
sb.append(" success: ");
sb.append(tm.getSuccessPercentage());
sb.append("%");
}
}
log(sb.toString());
}
}
|