本文整理汇总了Java中org.testng.TestNG.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java TestNG.addListener方法的具体用法?Java TestNG.addListener怎么用?Java TestNG.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.testng.TestNG
的用法示例。
在下文中一共展示了TestNG.addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addListener
import org.testng.TestNG; //导入方法依赖的package包/类
/**
*
* @param testNG testNG instance
* @param existingListeners existing listeners list (TestListeners/SuiteListeners/ReportListeners/... list)
* @param listenerClassName listener canonical name
*/
private void addListener(
TestNG testNG,
List<?> existingListeners,
String listenerClassName ) {
Class<?> listenerClass;
try {
listenerClass = Class.forName(listenerClassName);
if (!isListenerAlreadyAttached(existingListeners, listenerClass)) {
Object listener = listenerClass.newInstance();
testNG.addListener(listener);
logger.info("Successfully attached listener \"" + listenerClassName + "\".");
} else {
logger.info("Skip attaching listener \"" + listenerClassName
+ "\". It's already attached!");
}
} catch (Exception e) {
logger.error("Error attaching listener: \"" + listenerClassName + "\".", e);
}
}
示例2: verifyHappyPath
import org.testng.TestNG; //导入方法依赖的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: run
import org.testng.TestNG; //导入方法依赖的package包/类
@Override
public void run() {
try {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { HybridTest.class });
//testng.settes
testng.addListener(tla);
testng.run();
}catch (Exception e) {
e.printStackTrace();
System.out.println("Thread " + threadName + " interrupted.");
}
System.out.println("Thread " + threadName + " exiting.");
}
示例4: verifyCanNotCapture
import org.testng.TestNG; //导入方法依赖的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.TestNG; //导入方法依赖的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.TestNG; //导入方法依赖的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.TestNG; //导入方法依赖的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.TestNG; //导入方法依赖的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: runTestAndAssertCounters
import org.testng.TestNG; //导入方法依赖的package包/类
@Test
public void runTestAndAssertCounters() throws Exception {
final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
final TestNG testNG = new TestNG();
testNG.addListener(listener);
testNG.setTestClasses(new Class<?>[] { this.clazz });
testNG.setVerbose(0);
testNG.run();
assertEquals("Verifying number of test starts for test class [" + this.clazz + "].",
this.expectedTestStartCount, listener.testStartCount);
assertEquals("Verifying number of successful tests for test class [" + this.clazz + "].",
this.expectedTestSuccessCount, listener.testSuccessCount);
assertEquals("Verifying number of failures for test class [" + this.clazz + "].", this.expectedFailureCount,
listener.testFailureCount);
assertEquals("Verifying number of failed configurations for test class [" + this.clazz + "].",
this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:FailingBeforeAndAfterMethodsTestNGTests.java
示例10: runTestClassAndAssertStats
import org.testng.TestNG; //导入方法依赖的package包/类
private void runTestClassAndAssertStats(Class<?> testClass, int expectedTestCount) {
final int expectedTestFailureCount = 0;
final int expectedTestStartedCount = expectedTestCount;
final int expectedTestFinishedCount = expectedTestCount;
final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
final TestNG testNG = new TestNG();
testNG.addListener(listener);
testNG.setTestClasses(new Class<?>[] { testClass });
testNG.setVerbose(0);
testNG.run();
assertEquals("Failures for test class [" + testClass + "].", expectedTestFailureCount,
listener.testFailureCount);
assertEquals("Tests started for test class [" + testClass + "].", expectedTestStartedCount,
listener.testStartCount);
assertEquals("Successful tests for test class [" + testClass + "].", expectedTestFinishedCount,
listener.testSuccessCount);
}
示例11: runTestAndAssertCounters
import org.testng.TestNG; //导入方法依赖的package包/类
@Test
public void runTestAndAssertCounters() throws Exception {
final FailureTrackingTestListener listener = new FailureTrackingTestListener();
final TestNG testNG = new TestNG();
testNG.addListener(listener);
testNG.setTestClasses(new Class<?>[] { this.clazz });
testNG.setVerbose(0);
testNG.run();
assertEquals("Verifying number of test starts for test class [" + this.clazz + "].",
this.expectedTestStartCount, listener.testStartCount);
assertEquals("Verifying number of successful tests for test class [" + this.clazz + "].",
this.expectedTestSuccessCount, listener.testSuccessCount);
assertEquals("Verifying number of failures for test class [" + this.clazz + "].", this.expectedFailureCount,
listener.testFailureCount);
assertEquals("Verifying number of failed configurations for test class [" + this.clazz + "].",
this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount);
}
示例12: testRunSampleTestNGClass
import org.testng.TestNG; //导入方法依赖的package包/类
@Test
public void testRunSampleTestNGClass() throws Exception {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {TestSubClass.class});
testng.addListener(tla);
testng.run();
for (String item : this.outputFiles) {
File file = new File(item);
Assert.assertTrue(
"The element '" + file.getAbsolutePath() + "' wasn't found",
file.exists());
}
for (String method : this.expectedMethods) {
Assert.assertTrue(
"Unable to find the call of method: " + method,
AerialGluCode.getCallsList().contains(method));
}
}
示例13: execute
import org.testng.TestNG; //导入方法依赖的package包/类
@Override
public TestExecutionResult execute( Class<?> testClass, String testMethod ) {
TestNgExecutionResult result = new TestNgExecutionResult();
ScenarioTestListenerAdapter testListenerAdapter = new ScenarioTestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses( new Class<?>[] { testClass } );
if( testMethod != null ) {
methodName = testMethod;
testng.addMethodSelector( MethodSelector.class.getName(), 10 );
}
testng.addListener( testListenerAdapter );
Config.config().setReportEnabled( false );
testng.run();
Config.config().setReportEnabled( true );
result.reportModel = testListenerAdapter.reportModel;
result.testResults = testListenerAdapter.testResults;
return result;
}
示例14: runTests
import org.testng.TestNG; //导入方法依赖的package包/类
private void runTests() {
TestNG testNg = new TestNG();
testNg.setOutputDirectory(testReportDir.getAbsolutePath());
testNg.setDefaultSuiteName(options.getDefaultSuiteName());
testNg.setDefaultTestName(options.getDefaultTestName());
testNg.setParallel(options.getParallel());
testNg.setThreadCount(options.getThreadCount());
invokeVerifiedMethod(testNg, "setConfigFailurePolicy", String.class, options.getConfigFailurePolicy(), TestNGOptions.DEFAULT_CONFIG_FAILURE_POLICY);
invokeVerifiedMethod(testNg, "setPreserveOrder", boolean.class, options.getPreserveOrder(), false);
invokeVerifiedMethod(testNg, "setGroupByInstances", boolean.class, options.getGroupByInstances(), false);
testNg.setUseDefaultListeners(options.getUseDefaultListeners());
testNg.setVerbose(0);
testNg.setGroups(CollectionUtils.join(",", options.getIncludeGroups()));
testNg.setExcludedGroups(CollectionUtils.join(",", options.getExcludeGroups()));
//adding custom test listeners before Gradle's listeners.
//this way, custom listeners are more powerful and, for example, they can change test status.
for (String listenerClass : options.getListeners()) {
try {
testNg.addListener(applicationClassLoader.loadClass(listenerClass).newInstance());
} catch (Throwable e) {
throw new GradleException(String.format("Could not add a test listener with class '%s'.", listenerClass), e);
}
}
if (!options.getIncludedTests().isEmpty()) {
testNg.addListener(new SelectedTestsFilter(options.getIncludedTests()));
}
if (!suiteFiles.isEmpty()) {
testNg.setTestSuites(GFileUtils.toPaths(suiteFiles));
} else {
testNg.setTestClasses(testClasses.toArray(new Class[0]));
}
testNg.addListener((Object) adaptListener(new TestNGTestResultProcessorAdapter(resultProcessor, idGenerator, timeProvider)));
testNg.run();
}
示例15: run
import org.testng.TestNG; //导入方法依赖的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;
}