Java Code Examples for org.testng.TestNG#setUseDefaultListeners()

The following examples show how to use org.testng.TestNG#setUseDefaultListeners() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllureTestListenerSuiteNameTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    resultsDir = folder.newFolder();
    AllureResultsUtils.setResultsDirectory(resultsDir);

    List<String> suites = new ArrayList<>();
    URL resource = getClass().getClassLoader().getResource("suite3.xml");
    assertNotNull("could not find suite3.xml", resource);

    //noinspection ConstantConditions
    suites.add(resource.getFile());

    TestNG testNG = new TestNG();
    testNG.setTestSuites(suites);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
Example 2
Source File: TestNGTests.java    From quickperf with Apache License 2.0 5 votes vote down vote up
public static TestNGTests createInstance(Class<?> testClass) {
    TestNG testNG = new TestNG();
    testNG.setUseDefaultListeners(false);
    testNG.setVerbose(0);
    Class[] testClasses = {testClass};
    testNG.setTestClasses(testClasses);

    TestListenerAdapter testListenerAdapter = new TestListenerAdapter();
    testNG.addListener(testListenerAdapter);

    return new TestNGTests(testNG, testListenerAdapter);
}
 
Example 3
Source File: TestNGRunner.java    From agent with MIT License 5 votes vote down vote up
private static TestNG run(Class[] testClasses, List<Class<? extends ITestNGListener>> listenerClasses) {
    TestNG testNG = new TestNG();
    testNG.setTestClasses(testClasses);
    testNG.setListenerClasses(listenerClasses);
    testNG.setUseDefaultListeners(false); // 不用默认监听器,不会自动生成testng的默认报告
    testNG.run();
    return testNG;
}
 
Example 4
Source File: TestNGShouldFailWhenMockitoListenerFailsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private TestNG new_TestNG_with_failure_recorder_for(Class<?>... testNGClasses) {
    TestNG testNG = new TestNG();
    testNG.setVerbose(0);
    testNG.setUseDefaultListeners(false);
    testNG.addListener(failureRecorder);

    testNG.setTestClasses(testNGClasses);
    return testNG;
}
 
Example 5
Source File: AllureTestListenerConfigMethodsTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {
    resultsDir = Files.createTempDirectory(ALLURE_RESULTS);
    AllureResultsUtils.setResultsDirectory(resultsDir.toFile());

    List<XmlSuite> suites = new ArrayList<>();
    for (ConfigMethodType type : ConfigMethodType.values()) {
        suites.add(createSuite(type.getTitle()));
    }

    TestNG testNG = new TestNG();
    testNG.setXmlSuites(suites);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
Example 6
Source File: AllureTestListenerXmlValidationTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    resultsDir = Files.createTempDirectory(ALLURE_RESULTS);
    AllureResultsUtils.setResultsDirectory(resultsDir.toFile());

    TestNG testNG = new TestNG();
    testNG.setDefaultSuiteName(DEFAULT_SUITE_NAME);
    testNG.setTestClasses(new Class[]{TestDataClass.class});
    testNG.setUseDefaultListeners(false);

    testNG.run();
}
 
Example 7
Source File: AllureTestListenerMultipleSuitesTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    resultsDir = Files.createTempDirectory(ALLURE_RESULTS);
    AllureResultsUtils.setResultsDirectory(resultsDir.toFile());
    List<String> suites = Lists.newArrayList();
    suites.add(getClass().getResource(SUITE1).getFile());
    suites.add(getClass().getResource(SUITE2).getFile());
    TestNG testNG = new TestNG();
    testNG.setTestSuites(suites);
    testNG.setSuiteThreadPoolSize(2);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
Example 8
Source File: TestNGRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Throwable {
  for (String className : testClassNames) {

    Class<?> testClass = Class.forName(className);

    List<TestResult> results;
    if (!mightBeATestClass(testClass)) {
      results = Collections.emptyList();
    } else {
      results = new ArrayList<>();
      TestNG testng = new TestNG();
      testng.setUseDefaultListeners(false);
      testng.addListener(new FilteringAnnotationTransformer(results));
      testng.setTestClasses(new Class<?>[] {testClass});
      testng.addListener(new TestListener(results));
      // use default TestNG reporters ...
      testng.addListener(new SuiteHTMLReporter());
      testng.addListener((IReporter) new FailedReporter());
      testng.addListener(new XMLReporter());
      testng.addListener(new EmailableReporter());
      // ... except this replaces JUnitReportReporter ...
      testng.addListener(new JUnitReportReporterWithMethodParameters());
      // ... and we can't access TestNG verbosity, so we remove VerboseReporter
      testng.run();
    }

    writeResult(className, results);
  }
}
 
Example 9
Source File: ReactiveStreamsArquillianTck.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@Test
public void runAllTckTests() throws Throwable {
    TestNG testng = new TestNG();

    ObjectFactoryImpl delegate = new ObjectFactoryImpl();
    testng.setObjectFactory((IObjectFactory) (constructor, params) -> {
        if (constructor.getDeclaringClass().equals(ReactiveStreamsCdiTck.class)) {
            return tck;
        }
        else {
            return delegate.newInstance(constructor, params);
        }
    });

    testng.setUseDefaultListeners(false);
    ResultListener resultListener = new ResultListener();
    testng.addListener((ITestNGListener) resultListener);
    testng.setTestClasses(new Class[]{ ReactiveStreamsCdiTck.class });
    testng.setMethodInterceptor(new IMethodInterceptor() {
        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
            methods.sort(Comparator.comparing(m -> m.getInstance().getClass().getName()));
            return methods;
        }
    });
    testng.run();
    int total = resultListener.success.get() + resultListener.failed.get() + resultListener.skipped.get();
    System.out.println(String.format("Ran %d tests, %d passed, %d failed, %d skipped.", total, resultListener.success.get(),
        resultListener.failed.get(), resultListener.skipped.get()));
    System.out.println("Failed tests:");
    resultListener.failures.forEach(result -> {
        System.out.println(result.getInstance().getClass().getName() + "." + result.getMethod().getMethodName());
    });
    if (resultListener.failed.get() > 0) {
        if (resultListener.lastFailure.get() != null) {
            throw resultListener.lastFailure.get();
        }
        else {
            throw new Exception("Tests failed with no exception");
        }
    }
}
 
Example 10
Source File: TestNGRunner.java    From test-data-supplier with Apache License 2.0 4 votes vote down vote up
private static TestNG create() {
    final TestNG result = new TestNG();
    result.setUseDefaultListeners(false);
    result.setVerbose(0);
    return result;
}