Java 类org.testng.ITestListener 实例源码

项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked each time a test is skipped.
 *
 * @param result {@code ITestResult} containing information about the run test
 * @see ITestResult#SKIP
 */
@Override
public void onTestSkipped(ITestResult result) {

    // >>>>> ENTER workaround for TestNG bug
    // https://github.com/cbeust/testng/issues/1602
    ITestContext context = result.getTestContext();
    IInvokedMethod method = new InvokedMethod(
                    result.getTestClass(), result.getMethod(), System.currentTimeMillis(), result);

    beforeInvocation(method, result, context);
    // <<<<< LEAVE workaround for TestNG bug

    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onTestSkipped(result);
        }
    }
}
项目:Reer    文件:TestNGListenerAdapterFactory.java   
public ITestListener createAdapter(ITestListener listener) {
    Class<?> testNG6Class = tryLoadClass("org.testng.IConfigurationListener2");
    if (testNG6Class != null) {
        return createProxy(testNG6Class, listener);
    }

    Class<?> testNG5Class = tryLoadClass("org.testng.internal.IConfigurationListener");
    if (testNG5Class != null) {
        return createProxy(testNG5Class, listener);
    }

    throw new UnsupportedOperationException("Neither found interface 'org.testng.IConfigurationListener2' nor interface 'org.testng.internal.IConfigurationListener'. Which version of TestNG are you using?");
}
项目:ats-framework    文件:AtsTestngSuiteListener.java   
public void onStart( ISuite suite ) {

        // get the run name specified by the user
        String runName = CommonConfigurator.getInstance().getRunName();
        if (runName.equals(CommonConfigurator.DEFAULT_RUN_NAME)) {
            // the user did not specify a run name, use the one from TestNG
            runName = suite.getName();
        }

        // the following is needed in case when more than one RUN are executed sequentially
        // we need to clear some temporary data in the other listener we use
        TestNG testNgInstance = TestNG.getDefault();
        // cleanup the class level listener
        new AtsTestngClassListener().resetTempData();
        // cleanup the test level listener
        for (ITestListener listener : testNgInstance.getTestListeners()) {
            if (listener instanceof AtsTestngTestListener) {
                ((AtsTestngTestListener) listener).resetTempData();
            }
        }

        // start a new run
        String hostNameIp = "";
        try {
            InetAddress addr = InetAddress.getLocalHost();
            hostNameIp = addr.getHostName() + "/" + addr.getHostAddress();

        } catch (UnknownHostException uhe) {
            hostNameIp = null;
        }

        logger.startRun(runName, CommonConfigurator.getInstance().getOsName(),
                        CommonConfigurator.getInstance().getProductName(),
                        CommonConfigurator.getInstance().getVersionName(),
                        CommonConfigurator.getInstance().getBuildName(), hostNameIp);

        logSystemInformation();
        logClassPath();
    }
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked each time a test succeeds.
 *
 * @param result {@code ITestResult} containing information about the run test
 * @see ITestResult#SUCCESS
 */
@Override
public void onTestSuccess(ITestResult result) {
    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onTestSuccess(result);
        }
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked each time a test fails.
 *
 * @param result {@code ITestResult} containing information about the run test
 * @see ITestResult#FAILURE
 */
@Override
public void onTestFailure(ITestResult result) {
    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onTestFailure(result);
        }
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked after the test class is instantiated and before
 * any configuration method is called.
 * 
 * @param context context for the test run
 */
@Override
public void onStart(ITestContext context) {
    synchronized (testListeners) {
        for (ITestListener testListener : Lists.reverse(testListeners)) {
            testListener.onStart(context);
        }
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked after all the tests have run and all their
 * Configuration methods have been called.
 * 
 * @param context context for the test run
 */
@Override
public void onFinish(ITestContext context) {
    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onFinish(context);
        }
    }
}
项目:video-recorder-java    文件:TestNGVideoListenerTest.java   
@Test
@Video()
public void shouldBeRecordingIfCustomVideoAnnotation() {
  System.setProperty("video.save.mode","FAILED_ONLY");
  System.setProperty("recorder.type","FFMPEG");

  ITestResult result = prepareMock(TestNgCustomVideoListenerTest.class, testMethod);
  ITestListener listener = new CustomVideoListener();
  listener.onTestStart(result);
  sleep(5);
  listener.onTestFailure(result);
  File file = MonteRecorder.getLastRecording();
  assertTrue(file.exists());
}
项目:Pushjet-Android    文件:TestNGListenerAdapterFactory.java   
public ITestListener createAdapter(ITestListener listener) {
    Class<?> testNG6Class = tryLoadClass("org.testng.IConfigurationListener2");
    if (testNG6Class != null) {
        return createProxy(testNG6Class, listener);
    }

    Class<?> testNG5Class = tryLoadClass("org.testng.internal.IConfigurationListener");
    if (testNG5Class != null) {
        return createProxy(testNG5Class, listener);
    }

    throw new UnsupportedOperationException("Neither found interface 'org.testng.IConfigurationListener2' nor interface 'org.testng.internal.IConfigurationListener'. Which version of TestNG are you using?");
}
项目:Pushjet-Android    文件:TestNGListenerAdapterFactory.java   
public ITestListener createAdapter(ITestListener listener) {
    Class<?> testNG6Class = tryLoadClass("org.testng.IConfigurationListener2");
    if (testNG6Class != null) {
        return createProxy(testNG6Class, listener);
    }

    Class<?> testNG5Class = tryLoadClass("org.testng.internal.IConfigurationListener");
    if (testNG5Class != null) {
        return createProxy(testNG5Class, listener);
    }

    throw new UnsupportedOperationException("Neither found interface 'org.testng.IConfigurationListener2' nor interface 'org.testng.internal.IConfigurationListener'. Which version of TestNG are you using?");
}
项目:wtf-core    文件:WTFTest.java   
public static void addTestListenerIfNotAddedBefore(TestRunner tr,
        Class<?> listenerClass) throws IllegalAccessException,
        InstantiationException {
    for (ITestListener listnr : tr.getTestListeners()) {
        if (listenerClass.isInstance(listnr)) {
            return;
        }
    }
    tr.addTestListener((ITestListener) listenerClass.newInstance());
}
项目:Reer    文件:TestNGTestClassProcessor.java   
private ITestListener adaptListener(ITestListener listener) {
    TestNGListenerAdapterFactory factory = new TestNGListenerAdapterFactory(applicationClassLoader);
    return factory.createAdapter(listener);
}
项目:Reer    文件:TestNGListenerAdapterFactory.java   
private ITestListener createProxy(Class<?> configListenerClass, final ITestListener listener) {
    Class<?>[] interfaces = new Class<?>[]{ITestListener.class, ISuiteListener.class, configListenerClass};
    return (ITestListener) Proxy.newProxyInstance(classLoader, interfaces, new AdaptedListener(listener));
}
项目:Reer    文件:TestNGListenerAdapterFactory.java   
private AdaptedListener(ITestListener delegate) {
    this.delegate = delegate;
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked each time before a test will be invoked.
 * The {@code ITestResult} is only partially filled with the references to
 * class, method, start millis and status.
 *
 * @param result the partially filled {@code ITestResult}
 * @see ITestResult#STARTED
 */
@Override
public void onTestStart(ITestResult result) {
    synchronized(testListeners) {
        for (ITestListener testListener : Lists.reverse(testListeners)) {
            testListener.onTestStart(result);
        }
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [ITestListener]
 * Invoked each time a method fails but has been annotated with
 * successPercentage and this failure still keeps it within the
 * success percentage requested.
 *
 * @param result {@code ITestResult} containing information about the run test
 * @see ITestResult#SUCCESS_PERCENTAGE_FAILURE
 */
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
    synchronized (testListeners) {
        for (ITestListener testListener : testListeners) {
            testListener.onTestFailedButWithinSuccessPercentage(result);
        }
    }
}