类org.testng.xml.XmlInclude源码实例Demo

下面列出了怎么用org.testng.xml.XmlInclude的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: AppiumTestDistribution   文件: MyTestExecutor.java
private List<XmlInclude> constructIncludes(List<Method> methods) {
    List<XmlInclude> includes = new ArrayList<>();
    for (Method m : methods) {
        includes.add(new XmlInclude(m.getName()));
    }
    return includes;
}
 
源代码2 项目: pitest   文件: TestNGTestUnit.java
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;
}
 
源代码3 项目: carina   文件: CarinaListener.java
private List<XmlInclude> constructIncludes(String... methodNames) {
    List<XmlInclude> includes = new ArrayList<XmlInclude>();
    for (String eachMethod : methodNames) {
        includes.add(new XmlInclude(eachMethod));
    }
    return includes;
}
 
源代码4 项目: qaf   文件: TestRunner.java
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()]);
}
 
源代码5 项目: carina   文件: CarinaListener.java
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 + "'");
            }
        }
    }
 
 类所在包
 同包方法