@Override public int compare(ITestResult o1, ITestResult o2) { int result = o1.getTestClass().getName() .compareTo(o2.getTestClass().getName()); if (result == 0) { result = o1.getMethod().getMethodName() .compareTo(o2.getMethod().getMethodName()); } return result; } };
private static Throwable getConfigFailureException(ITestContext context) { for (IInvokedMethod method : context.getSuite().getAllInvokedMethods()) { ITestNGMethod m = method.getTestMethod(); if (m.isBeforeSuiteConfiguration() && (!method.getTestResult().isSuccess())) { return method.getTestResult().getThrowable(); } } return null; }
private void logResult(String status, ITestResult tr, String stackTrace) { logResult(status, tr.getName(), tr.getMethod().getDescription(), stackTrace, tr.getParameters(), tr.getMethod().getConstructorOrMethod().getParameterTypes()); }
@Override public int compare(ITestResult o1, ITestResult o2) { long t1 = o1.getEndMillis() - o1.getStartMillis(); long t2 = o2.getEndMillis() - o2.getStartMillis(); return (int) (t2 - t1); } });
ITestNGMethod method = tr.getMethod(); String name = method.getMethodName(); pw.append("<td title='").append(tr.getTestClass().getName()).append(".") .append(name) .append("()'>") String testClass = tr.getTestClass().getName(); if (testClass != null) { pw.append("<br>").append("Test class: ").append(testClass); String testName = tr.getTestName(); if (testName != null) { pw.append(" (").append(testName).append(")"); Object[] parameters = tr.getParameters(); if (parameters != null && parameters.length > 0) { pw.append("<br>Parameters: "); tw = tr.getThrowable(); String stackTrace; String fullStackTrace; long time = (tr.getEndMillis() - tr.getStartMillis()) / 1000; String strTime = Long.toString(time); pw.append("<td>").append(strTime).append("</td>\n"); Object instance = tr.getInstance(); pw.append("<td>").append(Objects.toString(instance)).append("</td>");
private static String prettyMsg(ITestResult result) { return "Test method : " + result.getTestClass().getRealClass().getName() + "." + result.getMethod().getMethodName() + "()" + ", Parameters : " + Arrays.toString(result.getParameters()); }
private Properties getTestResultAttributes(ITestResult testResult) { Properties attributes = new Properties(); if (!testResult.getMethod().isTest()) { attributes.setProperty(XMLReporterConfig.ATTR_IS_CONFIG, "true"); attributes.setProperty(XMLReporterConfig.ATTR_NAME, testResult.getMethod().getMethodName()); String testInstanceName = testResult.getTestName(); if (null != testInstanceName) { attributes.setProperty(XMLReporterConfig.ATTR_TEST_INSTANCE_NAME, testInstanceName); String description = testResult.getMethod().getDescription(); if (!Utils.isStringEmpty(description)) { attributes.setProperty(XMLReporterConfig.ATTR_DESC, description); attributes.setProperty(XMLReporterConfig.ATTR_METHOD_SIG, removeClassName(testResult.getMethod().toString())); String startTime = TimeUtils.timeInUTC(testResult.getStartMillis(), config.getTimestampFormat()); String endTime = TimeUtils.timeInUTC(testResult.getEndMillis(), config.getTimestampFormat()); attributes.setProperty(XMLReporterConfig.ATTR_STARTED_AT, startTime); attributes.setProperty(XMLReporterConfig.ATTR_FINISHED_AT, endTime); long duration = testResult.getEndMillis() - testResult.getStartMillis(); String strDuration = Long.toString(duration); attributes.setProperty(XMLReporterConfig.ATTR_DURATION_MS, strDuration); String groupNamesStr = Utils.arrayToString(testResult.getMethod().getGroups()); if (!Utils.isStringEmpty(groupNamesStr)) { attributes.setProperty(XMLReporterConfig.ATTR_GROUPS, groupNamesStr); String dependsOnStr = Utils.arrayToString(testResult.getMethod().getMethodsDependedUpon()); if (!Utils.isStringEmpty(dependsOnStr)) {
Method testMethod = testResult.getMethod().getConstructorOrMethod().getMethod(); boolean beforeCallbacksExecuted = false;
private void log(ITestResult tr, String status) { System.out.printf( "%-50s %-17s %-8s %-15s %8s%n", tr.getName(), tr.getTestClass().getRealClass().getSimpleName() .replaceAll("Test", ""), status, Arrays.toString(tr.getMethod().getGroups()), (tr.getEndMillis() - tr.getStartMillis()) + "ms"); } }
@Override public void onTestSkipped(ITestResult itr) { maps.put(itr.getMethod().getMethodName(), itr.getInstance()); }
void addSelenideErrorListener(ITestResult result) { boolean listenerAlreadyAdded = SelenideLogger.hasListener(LISTENER_SOFT_ASSERT); boolean hasSoftAssertListener = shouldIntercept(result.getTestClass().getRealClass()); boolean isTestMethod = shouldIntercept(result.getMethod().getConstructorOrMethod().getMethod()); if (hasSoftAssertListener && isTestMethod && !listenerAlreadyAdded) { SelenideLogger.addListener(LISTENER_SOFT_ASSERT, new ErrorsCollector()); } else if (hasSoftAssertListener && !listenerAlreadyAdded) { SelenideLogger.addListener(LISTENER_SOFT_ASSERT, new ErrorsCollector()); } }
private void createElement(XMLStringBuffer doc, ITestResult tr) { long elapsedTimeMillis= tr.getEndMillis() - tr.getStartMillis(); Properties attrs= getPropertiesFor(tr.getMethod(), elapsedTimeMillis); if (tr.getMethod().isTest()) { attrs.setProperty(XMLConstants.ATTR_NAME, tr.getName()); } 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); } doc.pop(); } else { doc.addEmptyElement(XMLConstants.TESTCASE, attrs); } }
/** * @return the test results that apply to one of the instances of the testMethod. */ private Set<ITestResult> keepSameInstances(ITestNGMethod method, Set<ITestResult> results) { Set<ITestResult> result = Sets.newHashSet(); for (ITestResult r : results) { Object o = method.getInstance(); // Keep this instance if 1) It's on a different class or 2) It's on the same class // and on the same instance Object instance = r.getInstance() != null ? r.getInstance() : r.getMethod().getInstance(); if (r.getTestClass() != method.getTestClass() || instance == o) result.add(r); } return result; }
@Override public int compare(ITestResult arg0, ITestResult arg1) { return arg0.getMethod().getMethodName().compareTo( arg1.getMethod().getMethodName()); }
@Override public void onTestFailure(ITestResult testResult) { String methodName = testResult.getMethod().getMethodName(); String raw = testResult.getThrowable().getMessage(); String actual = raw.split("\n")[1]; failures.put(methodName, actual); }
private void runAfterInvocationListeners(ITestResult tr) { InvokedMethod im = new InvokedMethod(tr.getTestClass(), tr.getMethod(), tr.getEndMillis(), tr); for (IInvokedMethodListener l: m_invokeListeners) { l.afterInvocation(im, tr); } }
protected static void invokeMethodConsideringTimeout(ITestNGMethod tm, ConstructorOrMethod method, Object targetInstance, Object[] params, ITestResult testResult) throws Throwable { if (MethodHelper.calculateTimeOut(tm) <= 0) { MethodInvocationHelper.invokeMethod(method.getMethod(), targetInstance, params); } else { MethodInvocationHelper.invokeWithTimeout(tm, targetInstance, params, testResult); if (!testResult.isSuccess()) { // A time out happened Throwable ex = testResult.getThrowable(); testResult.setStatus(ITestResult.FAILURE); testResult.setThrowable(ex.getCause() == null ? ex : ex.getCause()); throw testResult.getThrowable(); } } }
private void failIfErrors(ITestResult result) { ErrorsCollector errorsCollector = SelenideLogger.removeListener(LISTENER_SOFT_ASSERT); if (errorsCollector != null) { try { errorsCollector.failIfErrors(result.getTestClass().getName() + '.' + result.getName()); } catch (AssertionError e) { result.setStatus(ITestResult.FAILURE); result.setThrowable(e); } } } }
private static String getName(ITestResult result) { String testName = result.getName(); String methodName = result.getMethod().getConstructorOrMethod().getName(); String name; if (testName.contains(methodName)) { name = methodName; } else { name = testName + "#" + methodName; } if (result.getParameters().length != 0) { name = name + "(" + Joiner.on(",").useForNull("null").join(getParameterNames(result.getParameters())) + ")"; } return name; }