org.testng.TestNG.setTestSuites()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.testng.TestNG.setTestSuites()方法的一些代码示例,展示了TestNG.setTestSuites()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TestNG.setTestSuites()方法的具体详情如下:
包路径:org.testng.TestNG
类名称:TestNG
方法名:setTestSuites

TestNG.setTestSuites介绍

[英]Set the suites file names to be run by this TestNG object. This method tries to load and parse the specified TestNG suite xml files. If a file is missing, it is ignored.
[中]设置此TestNG对象要运行的套件文件名。此方法尝试加载和解析指定的TestNG套件xml文件。如果文件丢失,将忽略该文件。

代码示例

代码示例来源:origin: cbeust/testng

@Test(description = "Make sure that listeners defined in testng.xml are invoked")
 public void listenerInXmlShouldBeInvoked() {
  TestNG tng = create();
  tng.setTestSuites(Arrays.asList(getPathToResource("listener-in-xml.xml")));
  LListener.invoked = false;
  tng.run();
  Assert.assertTrue(LListener.invoked);
 }
}

代码示例来源:origin: cbeust/testng

@Test(priority = 2)
public void verifyWithListener() {
  TestNG testNG = create();
  testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284_withlistener.xml")));
  testNG.run();
  Assert.assertEquals(testNG.getStatus(), 0);
}

代码示例来源:origin: cbeust/testng

@Test(priority = 1)
public void verifyWithoutListener() {
  TestNG testNG = create();
  testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284_nolistener.xml")));
  testNG.run();
  Assert.assertEquals(testNG.getStatus(), 0);
}

代码示例来源:origin: cbeust/testng

@Test(priority = 3)
public void verifyWithChildSuite() {
  TestNG testNG = create();
  testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284.xml")));
  testNG.run();
  Assert.assertEquals(testNG.getStatus(), 0);
}

代码示例来源:origin: cbeust/testng

@Test
public void ensureThatParallelismAndThreadCountAreRallied() {
 TestNG testng = create();
 testng.setTestSuites(Collections.singletonList("src/test/resources/987.xml"));
 testng.setThreadCount(2);
 testng.setParallel(XmlSuite.ParallelMode.METHODS);
 testng.run();
 assertThat(Issue987TestSample.maps).hasSize(2);
 assertThat(Issue987TestSample.maps.values()).contains("method2", "method1");
}

代码示例来源:origin: cbeust/testng

@Test(description = "GITHUB-1834")
public void ensureDependenciesDefinedInSuiteAreHonored() throws IOException {
 File file = File.createTempFile("1834", ".xml");
 Files.writeFile(asSuite(), file);
 TestNG testng = create();
 testng.setTestSuites(Collections.singletonList(file.getAbsolutePath()));
 OutputGatheringListener listener = new OutputGatheringListener();
 testng.addListener(listener);
 testng.run();
 assertThat(listener.getConsoleLogs()).containsExactly("Uncached", "Cached");
}

代码示例来源:origin: cbeust/testng

@Test
 public void testMethod() {
  String suite = "src/test/resources/parametertest/1417.xml";
  TestNG testNG = new TestNG();
  testNG.setTestSuites(Collections.singletonList(suite));
  testNG.run();
  Assert.assertFalse(testNG.hasFailure());
  Assert.assertFalse(testNG.hasSkip());
  Assert.assertEquals(AnotherTestClassSample.getInstance().getBrowsername(), "chrome");
  List<String> actual = YetAnotherTestClassSample.getInstance().getBrowsers();
  Assert.assertEquals(actual.size(), 2);
  Assert.assertEquals(actual, Arrays.asList("safari", "safari"));
 }
}

代码示例来源:origin: cbeust/testng

@Test(description = "Checks to make sure parameters are inherited and overridden properly")
 public void parameterInheritanceAndOverriding() {
  TestNG tng = create();
  tng.setTestSuites(Arrays.asList(getPathToResource("parametertest/parent-suite.xml")));

  TestListenerAdapter tla = new TestListenerAdapter();
  tng.addListener((ITestNGListener) tla);

  tng.run();

  Assert.assertEquals(tla.getPassedTests().size(), 3);
 }
}

代码示例来源:origin: cbeust/testng

/**
 * Child suites and tests within different suites have same names
 */
@Test
public void check() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 String testngXmlPath = getPathToResource("checksuitesinitialization/parent-suite.xml");
 tng.setTestSuites(Collections.singletonList(testngXmlPath));
 tng.addListener(tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 4);
}

代码示例来源:origin: cbeust/testng

/**
 * Simple suite with no two tests with same name
 */
@Test
public void checkNoError() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 String testngXmlPath = getPathToResource("sanitycheck/test2.xml");
 tng.setTestSuites(Collections.singletonList(testngXmlPath));
 tng.addListener((ITestNGListener) tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 2);
}

代码示例来源:origin: cbeust/testng

/**
 * Child suites and tests within different suites have same names
 */
@Test(enabled = false)
public void checkNoErrorWtihChildSuites() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 String testngXmlPath = getPathToResource("sanitycheck/test-b.xml");
 tng.setTestSuites(Collections.singletonList(testngXmlPath));
 tng.addListener((ITestNGListener) tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 4);
}

代码示例来源:origin: cbeust/testng

/**
 * Child suites have different names
 */
@Test
public void checkChildSuites() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 String testngXmlPath = getPathToResource("sanitycheck/test-s-b.xml");
 tng.setTestSuites(Collections.singletonList(testngXmlPath));
 tng.addListener((ITestNGListener) tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 4);
}

代码示例来源:origin: cbeust/testng

@Test(description="Ensure that TestNG stops without running any tests if some class" +
  " included in suite is missing")
public void handleInvalidSuites() {
  TestListenerAdapter tla = new TestListenerAdapter();
  try {
   TestNG tng = create();
   String testngXmlPath = getPathToResource("suite1.xml");
   tng.setTestSuites(Collections.singletonList(testngXmlPath));
   tng.addListener((ITestNGListener) tla);
   tng.run();
  } catch (TestNGException ex) {
   Assert.assertEquals(tla.getPassedTests().size(), 0);
  }
}

代码示例来源:origin: cbeust/testng

@Test
  public void checkWithoutChildSuites() {
    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG tng = create();
    tng.setTestNames(Collections.singletonList("testGroup2"));
    tng.setTestSuites(Collections.singletonList(getPathToResource("testnames/upstream-suite.xml")));
    tng.addListener((ITestNGListener) tla);
    tng.run();
    Assert.assertEquals(tla.getFailedTests().size(), 0);
    Assert.assertEquals(tla.getPassedTests().size(), 1);
    Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "sampleOutputTest2");
  }
}

代码示例来源:origin: cbeust/testng

@Test
public void xmlXmlSuite() {
 TestNG tng = create();
 tng.setTestSuites(Collections.singletonList(getPathToResource("methodselector-in-xml.xml")));
 tng.addListener((ITestNGListener) m_tla);
 tng.run();
 validate(new String[] { "test2" });
}

代码示例来源:origin: cbeust/testng

private void runSuite(String suitePath)
{
 TestListenerAdapter tla = new TestListenerAdapter();
 boolean exceptionRaised = false;
 try {
  TestNG tng = create();
  String testngXmlPath = getPathToResource(suitePath);
  tng.setTestSuites(Collections.singletonList(testngXmlPath));
  tng.addListener((ITestNGListener) tla);
  tng.run();
 } catch (TestNGException ex) {
  exceptionRaised = true;
  Assert.assertEquals(tla.getPassedTests().size(), 0);
  Assert.assertEquals(tla.getFailedTests().size(), 0);
 }
 Assert.assertTrue(exceptionRaised);
}

代码示例来源:origin: cbeust/testng

@Test
  public void testMultipleInterceptorsWithPreserveOrder() {
   TestNG tng = create();
   tng.setTestSuites(Collections.singletonList(
     getPathToResource("/methodinterceptors/multipleinterceptors/multiple-interceptors.xml")));
   TestListenerAdapter tla = new TestListenerAdapter();
   tng.addListener((ITestNGListener) tla);
   tng.run();
   Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getDescription(), "abc");
  }
}

代码示例来源:origin: cbeust/testng

@Test(description = "Number of threads (2) is less than number of suites (3)")
public void suitesShouldRunInParallel3() {
 final int SUITE_THREAD_POOL_SIZE = 2;
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 tng.setSuiteThreadPoolSize(SUITE_THREAD_POOL_SIZE);
 tng.setTestSuites(Collections.singletonList(getPathToResource("suite-parallel-0.xml")));
 tng.addListener((ITestNGListener) tla);
 BaseThreadTest.initThreadLog();
 tng.run(); //Shouldn't not deadlock
 Assert.assertEquals(BaseThreadTest.getThreadCount(), SUITE_THREAD_POOL_SIZE);
}

代码示例来源:origin: cbeust/testng

/**
 * Child suites have same names
 */
@Test
public void checkChildSuitesFails() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 String testngXmlPath = getPathToResource("sanitycheck/test-s-a.xml");
 tng.setTestSuites(Collections.singletonList(testngXmlPath));
 tng.addListener((ITestNGListener) tla);
 tng.run();
 Assert.assertEquals(tla.getTestContexts().get(0).getSuite().getName(), "SanityCheck suites");
 Assert.assertEquals(tla.getTestContexts().get(1).getSuite().getName(), "SanityCheck suites");
 Assert.assertEquals(tla.getTestContexts().get(2).getSuite().getName(), "SanityCheck suites (0)");
 Assert.assertEquals(tla.getTestContexts().get(3).getSuite().getName(), "SanityCheck suites (0)");
}

代码示例来源:origin: cbeust/testng

private void runTest(int suiteThreadPoolSize, int expectedThreadCount,
   int expectedSuiteCount, Boolean randomizeSuites, List<String> paths) {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG tng = create();
 tng.setSuiteThreadPoolSize(suiteThreadPoolSize);
 tng.setTestSuites(paths);
 tng.addListener((ITestNGListener) tla);
 if (null != randomizeSuites) {
  tng.setRandomizeSuites(randomizeSuites);
 }
 BaseThreadTest.initThreadLog();
 tng.run();
 Assert.assertEquals(BaseThreadTest.getThreadCount(), expectedThreadCount,
   "Thread count expected:" + expectedThreadCount
   + " actual:" + BaseThreadTest.getThreadCount());
 Assert.assertEquals(BaseThreadTest.getSuitesMap().keySet().size(), expectedSuiteCount);
}

相关文章

TestNG类方法