org.testng.xml.XmlInclude Java Examples

The following examples show how to use org.testng.xml.XmlInclude. 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: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
private List<XmlInclude> constructIncludes(List<Method> methods) {
    List<XmlInclude> includes = new ArrayList<>();
    for (Method m : methods) {
        includes.add(new XmlInclude(m.getName()));
    }
    return includes;
}
 
Example #2
Source File: TestNGTestUnit.java    From pitest with Apache License 2.0 5 votes vote down vote up
private XmlSuite createSuite() {
  final XmlSuite suite = new XmlSuite();
  suite.setName(this.clazz.getName());
  suite.setSkipFailedInvocationCounts(true);
  final XmlTest test = new XmlTest(suite);
  test.setName(this.clazz.getName());
  final XmlClass xclass = new XmlClass(this.clazz.getName());
  test.setXmlClasses(Collections.singletonList(xclass));

  if (!this.includedTestMethods.isEmpty()) {
    final List<XmlInclude> xmlIncludedTestMethods = new ArrayList<>();
    for (final String includedTestMethod : this.includedTestMethods) {
      final XmlInclude includedMethod = new XmlInclude(includedTestMethod);
      xmlIncludedTestMethods.add(includedMethod);
    }
    xclass.setIncludedMethods(xmlIncludedTestMethods);
  }

  if (!this.config.getExcludedGroups().isEmpty()) {
    suite.setExcludedGroups(this.config.getExcludedGroups());
  }

  if (!this.config.getIncludedGroups().isEmpty()) {
    suite.setIncludedGroups(this.config.getIncludedGroups());
  }

  return suite;
}
 
Example #3
Source File: CarinaListener.java    From carina with Apache License 2.0 5 votes vote down vote up
private List<XmlInclude> constructIncludes(String... methodNames) {
    List<XmlInclude> includes = new ArrayList<XmlInclude>();
    for (String eachMethod : methodNames) {
        includes.add(new XmlInclude(eachMethod));
    }
    return includes;
}
 
Example #4
Source File: TestRunner.java    From qaf with MIT License 4 votes vote down vote up
private void privateRunJUnit(XmlTest xmlTest) {
  final ClassInfoMap cim = new ClassInfoMap(m_testClassesFromXml, false);
  final Set<Class<?>> classes = cim.getClasses();
  final List<ITestNGMethod> runMethods = Lists.newArrayList();
  List<IWorker<ITestNGMethod>> workers = Lists.newArrayList();
  // FIXME: directly referencing JUnitTestRunner which uses JUnit classes
  // may result in an class resolution exception under different JVMs
  // The resolution process is not specified in the JVM spec with a specific implementation,
  // so it can be eager => failure
  workers.add(new IWorker<ITestNGMethod>() {
    /**
     * @see TestMethodWorker#getTimeOut()
     */
    @Override
    public long getTimeOut() {
      return 0;
    }

    /**
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() {
      for(Class<?> tc: classes) {
        List<XmlInclude> includedMethods = cim.getXmlClass(tc).getIncludedMethods();
        List<String> methods = Lists.newArrayList();
        for (XmlInclude inc: includedMethods) {
            methods.add(inc.getName());
        }
        IJUnitTestRunner tr= ClassHelper.createTestRunner(TestRunner.this);
        tr.setInvokedMethodListeners(m_invokedMethodListeners);
        try {
          tr.run(tc, methods.toArray(new String[methods.size()]));
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
        finally {
          runMethods.addAll(tr.getTestMethods());
        }
      }
    }

    @Override
    public List<ITestNGMethod> getTasks() {
      throw new TestNGException("JUnit not supported");
    }

    @Override
    public int getPriority() {
      if (m_allTestMethods.length == 1) {
        return m_allTestMethods[0].getPriority();
      } else {
        return 0;
      }
    }

    @Override
    public int compareTo(IWorker<ITestNGMethod> other) {
      return getPriority() - other.getPriority();
    }
  });

  runJUnitWorkers(workers);
  m_allTestMethods= runMethods.toArray(new ITestNGMethod[runMethods.size()]);
}
 
Example #5
Source File: CarinaListener.java    From carina with Apache License 2.0 4 votes vote down vote up
private void checkHealth(ISuite suite, String className, String[] methods) {

        if (className.isEmpty()) {
            return;
        }

        // create runtime XML suite for health check
        XmlSuite xmlSuite = new XmlSuite();
        xmlSuite.setName("HealthCheck XmlSuite - " + className);

        XmlTest xmlTest = new XmlTest(xmlSuite);
        xmlTest.setName("HealthCheck TestCase");
        XmlClass xmlHealthCheckClass = new XmlClass();
        xmlHealthCheckClass.setName(className);

        // TestNG do not execute missed methods so we have to calulate expected
        // methods count to handle potential mistakes in methods naming
        int expectedMethodsCount = -1;
        if (methods != null) {
            // declare particular methods if they are provided
            List<XmlInclude> methodsToRun = constructIncludes(methods);
            expectedMethodsCount = methodsToRun.size();
            xmlHealthCheckClass.setIncludedMethods(methodsToRun);
        }

        xmlTest.setXmlClasses(Arrays.asList(new XmlClass[] { xmlHealthCheckClass }));
        xmlSuite.setTests(Arrays.asList(new XmlTest[] { xmlTest }));

        LOGGER.info("HealthCheck '" + className + "' is started.");
        LOGGER.debug("HealthCheck suite content:" + xmlSuite.toXml());

        // Second TestNG process to run HealthCheck
        TestNG testng = new TestNG();
        testng.setXmlSuites(Arrays.asList(xmlSuite));

        TestListenerAdapter tla = new TestListenerAdapter();
        testng.addListener(tla);

        testng.run();
        synchronized (this) {
            boolean passed = false;
            if (expectedMethodsCount == -1) {
                if (tla.getPassedTests().size() > 0 && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            } else {
                LOGGER.info("Expected passed tests count: " + expectedMethodsCount);
                if (tla.getPassedTests().size() == expectedMethodsCount && tla.getFailedTests().size() == 0
                        && tla.getSkippedTests().size() == 0) {
                    passed = true;
                }
            }
            if (passed) {
                LOGGER.info("HealthCheck suite '" + className + "' is finished successfully.");
            } else {
                throw new SkipException("Skip test(s) due to health check failures for '" + className + "'");
            }
        }
    }