Refine search
@Test public void birds() { String methodName = Reporter.getCurrentTestResult().getMethod().getMethodName(); Reporter.log(methodName); Assert.assertNotNull(methodName); }
public ITestResult registerSkippedTestResult( ITestNGMethod testMethod, long start, Throwable throwable) { ITestResult result = TestResult.newEndTimeAwareTestResult(testMethod, m_testContext, throwable, start); result.setStatus(ITestResult.STARTED); runTestResultListener(result); result.setStatus(TestResult.SKIP); Reporter.setCurrentTestResult(result); return result; }
ITestNGMethod method = tr.getMethod(); 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); List<String> output = Reporter.getOutput(tr); if (null != output && output.size() > 0) { pw.append("<br/>");
/** * Log the passed string to the HTML reports * @param s The message to log */ public static void log(String s) { log(s, getCurrentTestResult()); }
@Override public void onTestSkipped(ITestResult arg0) { Reporter.log(arg0.getTestClass().getName() + "." + arg0.getMethod().getMethodName() + " on thread " + Thread.currentThread().getId() + " skipped", true); }
@Override public void onTestFailure(ITestResult arg0) { Reporter.log(arg0.getTestClass().getName() + "." + arg0.getMethod().getMethodName() + " on thread " + Thread.currentThread().getId() + " failed", true); arg0.getThrowable().printStackTrace(); }
private void generateForResult(ITestResult ans, ITestNGMethod method) { Object[] parameters = ans.getParameters(); boolean hasParameters = parameters != null && parameters.length > 0; if (hasParameters) { List<String> msgs = Reporter.getOutput(ans); boolean hasReporterOutput = !msgs.isEmpty(); Throwable exception=ans.getThrowable(); boolean hasThrowable = exception!=null; if (hasReporterOutput||hasThrowable) { boolean wantsMinimalOutput = ans.getStatus()==ITestResult.SUCCESS; if(hasReporterOutput) { m_out.println("<h3>"
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (testResult.getStatus() != ITestResult.FAILURE) { return; } final IRetryAnalyzer retryAnalyzer = testResult.getMethod().getRetryAnalyzer(); if (retryAnalyzer != null && retryAnalyzer instanceof FlakyRetryAnalyzer && !((FlakyRetryAnalyzer) retryAnalyzer).shouldRetry()) { // Don't fail the build (flaky test), mark it as SKIPPED testResult.setStatus(ITestResult.SKIP); Reporter.setCurrentTestResult(testResult); } } }
@Override public void onTestFailure(ITestResult result) { IRetryAnalyzer analyzer = result.getMethod().getRetryAnalyzer(); if (analyzer != null && analyzer instanceof Retry) { result.setStatus(((Retry) analyzer).isRetryAvailable()? ITestResult.SKIP : ITestResult.FAILURE); Reporter.setCurrentTestResult(result); } }
private void logResult(Marker marker, ITestResult result, String message) { Reporter.log(message, true); getLogger().info(marker, message); Throwable throwable = result.getThrowable(); if (throwable != null) { getLogger().info(marker, result.getTestName() + ": " + throwable.getMessage()); getLogger().debug(marker, result.getTestName(), throwable); } }
static void performTest(String username, String password) { String method = Reporter.getCurrentTestResult().getMethod().getMethodName(); String txt = String.format("%s() Assertion for (%s, %s)", method, username, password); fail(txt); }
@Test public void failedTest() { Reporter.getCurrentTestResult().setStatus(ITestResult.FAILURE); }
m_notifier.addInvokedMethod(invokedMethod); try { Reporter.setCurrentTestResult(testResult); ConstructorOrMethod method = tm.getConstructorOrMethod(); testResult.setStatus(ITestResult.SUCCESS); return; throw new TestNGException(ex); } finally { testResult.setEndMillis(System.currentTimeMillis()); Reporter.setCurrentTestResult(testResult); runInvokedMethodListeners(AFTER_INVOCATION, invokedMethod, testResult); Reporter.setCurrentTestResult(null);
public static synchronized List<String> getOutput(ITestResult tr) { List<String> result = Lists.newArrayList(); if (tr == null) { //guard against a possible NPE in scenarios wherein the test result object itself could be a null value. return result; } List<Integer> lines = m_methodOutputMap.get(tr.hashCode()); if (lines != null) { for (Integer n : lines) { result.add(getOutput().get(n)); } } return result; } }
@Test public void pass() { Assert.assertEquals(Reporter.getCurrentTestResult().getAttribute("before"), 10); Assert.assertEquals(m_testResult.getAttribute("before"), 10); }
testResult.setStatus(ITestResult.STARTED); Reporter.setCurrentTestResult(testResult); Reporter.setCurrentTestResult(null);
@Test public void reportLogShouldBeAvailableWithListener() { TestNG tng = create(ListenerReporterSample.class); InvokedMethodNameListener listener = new InvokedMethodNameListener(); tng.addListener(listener); Reporter.clear(); tng.run(); assertThat(listener.getFailedMethodNames()).isEmpty(); assertThat(listener.getSkippedMethodNames()).isEmpty(); assertThat(listener.getSucceedMethodNames()).containsExactly("testMethod"); assertThat(Reporter.getOutput()).hasSize(2); }
private static void addVerificationFailure(Throwable e) { List verificationFailures = getVerificationFailures(); verificationFailuresMap.put(Reporter.getCurrentTestResult(), verificationFailures); verificationFailures.add(e); }
@Override public void onTestStart(ITestResult arg0) { Reporter.log("about to start test " + arg0.getTestClass().getName() + "." + arg0.getMethod().getMethodName() + " on thread " + Thread.currentThread().getId(), true); }