本文整理汇总了Java中org.testng.ITestNGListener类的典型用法代码示例。如果您正苦于以下问题:Java ITestNGListener类的具体用法?Java ITestNGListener怎么用?Java ITestNGListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITestNGListener类属于org.testng包,在下文中一共展示了ITestNGListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processLinkedListeners
import org.testng.ITestNGListener; //导入依赖的package包/类
/**
* Process the {@link LinkedListeners} annotation of the specified test class.
*
* @param testClass test class
*/
private void processLinkedListeners(Class<?> testClass) {
Objects.requireNonNull(testClass, "[testClass] must be non-null");
LinkedListeners annotation = testClass.getAnnotation(LinkedListeners.class);
if (null != annotation) {
Class<?> markedClass = testClass;
while (null == markedClass.getDeclaredAnnotation(LinkedListeners.class)) {
markedClass = markedClass.getSuperclass();
}
if ( ! markedClasses.contains(markedClass)) {
markedClasses.add(markedClass);
for (Class<? extends ITestNGListener> listener : annotation.value()) {
attachListener(listener, null);
}
}
}
}
示例2: verifyHappyPath
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void verifyHappyPath() {
ListenerChain lc = new ListenerChain();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
testNG.addListener((ITestNGListener) lc);
testNG.addListener((ITestNGListener) tla);
testNG.setGroups("testPassed");
testNG.run();
assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
ITestResult result = tla.getPassedTests().get(0);
assertNull(UnitTestArtifact.getCaptureState(result), "Artifact provider capture state should be 'null'");
assertNull(UnitTestCapture.getArtifactPath(result), "Artifact capture should not have been requested");
}
示例3: verifyCaptureOnFailure
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void verifyCaptureOnFailure() {
ListenerChain lc = new ListenerChain();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
testNG.addListener((ITestNGListener) lc);
testNG.addListener((ITestNGListener) tla);
testNG.setGroups("testFailed");
testNG.run();
assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
ITestResult result = tla.getFailedTests().get(0);
assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
示例4: verifyCanNotCapture
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void verifyCanNotCapture() {
ListenerChain lc = new ListenerChain();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
testNG.addListener((ITestNGListener) lc);
testNG.addListener((ITestNGListener) tla);
testNG.setGroups("canNotCapture");
testNG.run();
assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
ITestResult result = tla.getFailedTests().get(0);
assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAN_NOT_CAPTURE, "Incorrect artifact provider capture state");
assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
示例5: verifyWillNotCapture
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void verifyWillNotCapture() {
ListenerChain lc = new ListenerChain();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
testNG.addListener((ITestNGListener) lc);
testNG.addListener((ITestNGListener) tla);
testNG.setGroups("willNotCapture");
testNG.run();
assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
ITestResult result = tla.getFailedTests().get(0);
assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_FAILED, "Incorrect artifact provider capture state");
assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
示例6: verifyOnDemandCapture
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void verifyOnDemandCapture() {
ListenerChain lc = new ListenerChain();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
testNG.addListener((ITestNGListener) lc);
testNG.addListener((ITestNGListener) tla);
testNG.setGroups("onDemandCapture");
testNG.run();
assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
ITestResult result = tla.getPassedTests().get(0);
assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
示例7: testAttributeHandOff
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void testAttributeHandOff() {
ExecutionFlowController efc = new ExecutionFlowController();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{HappyPathClass.class});
testNG.addListener((ITestNGListener) efc);
testNG.addListener((ITestNGListener) tla);
testNG.run();
assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");
assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
assertEquals(HappyPathClass.fromBefore, HappyPathClass.VALUE, "Incorrect [before] value");
assertEquals(HappyPathClass.fromMethod, HappyPathClass.VALUE, "Incorrect [method] value");
assertEquals(HappyPathClass.fromAfter, HappyPathClass.VALUE, "Incorrect [after] value");
}
示例8: testSkipFromMethod
import org.testng.ITestNGListener; //导入依赖的package包/类
@Test
public void testSkipFromMethod() {
ExecutionFlowController efc = new ExecutionFlowController();
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[]{SkipFromMethod.class});
testNG.addListener((ITestNGListener) efc);
testNG.addListener((ITestNGListener) tla);
testNG.run();
assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");
assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
assertEquals(tla.getSkippedTests().get(0).getName(), "testMethod", "Incorrect skipped test name");
assertEquals(SkipFromMethod.fromBefore, SkipFromMethod.VALUE, "Incorrect [before] value");
assertEquals(SkipFromMethod.fromMethod, SkipFromMethod.VALUE, "Incorrect [method] value");
assertEquals(SkipFromMethod.fromAfter, SkipFromMethod.VALUE, "Incorrect [after] value");
}
示例9: isAnnotated
import org.testng.ITestNGListener; //导入依赖的package包/类
private boolean isAnnotated(Class<?> realClass)
{
Listeners listeners = realClass.getAnnotation(Listeners.class);
if (listeners == null)
{
return false;
}
for (Class<? extends ITestNGListener> listenerClass : listeners.value())
{
if (listenerClass.equals(MockitoTestNgListener.class))
{
return true;
}
}
return false;
}
示例10: getLinkedListener
import org.testng.ITestNGListener; //导入依赖的package包/类
/**
* Get the listener of the specified type that's attached to the listener chain.
*
* @param <T> listener type
* @param listenerType listener type
* @return listener of the specified type
*/
public static <T extends ITestNGListener> T getLinkedListener(Class<T> listenerType) {
ITestResult testResult = Reporter.getCurrentTestResult();
Optional<T> optListener =
ListenerChain.getAttachedListener(testResult, listenerType);
if (optListener.isPresent()) {
return optListener.get();
}
throw new IllegalStateException(listenerType.getSimpleName() + " listener wasn't found on the listener chain");
}
示例11: run
import org.testng.ITestNGListener; //导入依赖的package包/类
private InvokedMethodNameListener run(final String suitePath, final Supplier<BeforeMethodListener> listenerSupplier) {
final TestNG tng = create();
final InvokedMethodNameListener nameListener = new InvokedMethodNameListener();
final BeforeMethodListener spyListener = listenerSupplier.get();
tng.addListener((ITestNGListener) nameListener);
tng.addListener((ITestNGListener) spyListener);
tng.setTestSuites(singletonList(suitePath));
tng.run();
return nameListener;
}
示例12: with
import org.testng.ITestNGListener; //导入依赖的package包/类
/**
* Constructs new {@link TestNGEngine} object with wanted listeners.
*
* @param listeners an instance (or instances) of engine's listeners
* @return an instance of {@link TestNGEngine}
*/
@Override
public TestNGEngine with(ITestNGListener... listeners) {
final TestNG testNG = new TestNG(false);
Arrays.stream(listeners).forEach(testNG::addListener);
return new TestNGEngine(testNG, this.tests);
}
示例13: with
import org.testng.ITestNGListener; //导入依赖的package包/类
/**
* Constructs new {@link TestNGKernel} object with wanted listeners.
*
* @param listeners an instance (or instances) of engine's listeners
* @return an instance of {@link TestNGKernel}
*/
@Override
public TestNGKernel with(ITestNGListener... listeners) {
final TestNGKernel kernel = new TestNGKernel(this.suite);
Arrays.stream(listeners).forEach(kernel.engine::addListener);
return kernel;
}
示例14: prepare
import org.testng.ITestNGListener; //导入依赖的package包/类
@BeforeMethod(description = "Configure TestNG engine")
public void prepare() {
results = new AllureResultsWriterStub();
lifecycle = new AllureLifecycle(results);
AllureTestNg adapter = new AllureTestNg(lifecycle);
testNg = new TestNG(false);
testNg.addListener((ITestNGListener) adapter);
}
示例15: getAttachedListener
import org.testng.ITestNGListener; //导入依赖的package包/类
/**
* Get reference to an instance of the specified listener type.
*
* @param <T> listener type
* @param suite TestNG suite object
* @param listenerType listener type
* @return optional listener instance
*/
public static <T extends ITestNGListener> Optional<T>
getAttachedListener(ISuite suite, Class<T> listenerType) {
Objects.requireNonNull(suite, "[suite] must be non-null");
Objects.requireNonNull(listenerType, "[listenerType] must be non-null");
ListenerChain chain = (ListenerChain) suite.getAttribute(LISTENER_CHAIN);
Objects.requireNonNull(chain, "Specified suite has no ListenerChain");
return chain.getAttachedListener(listenerType);
}