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

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

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

TestNG.<init>介绍

[英]Default constructor. Setting also usage of default listeners/reporters.
[中]

代码示例

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

@BeforeMethod
public void setUp() {
 m_testNg = new TestNG();
 m_testNg.setVerbose(0);
}

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

private static TestNG createTestNG(Path outputDir) {
 TestNG result = new TestNG();
 result.setOutputDirectory(outputDir.toAbsolutePath().toString());
 result.setVerbose(-1);
 return result;
}

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

public static TestNG create() {
 TestNG result = new TestNG();
 result.setUseDefaultListeners(false);
 result.setVerbose(0);
 return result;
}

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

@Test
public void withFactory() {
 TestNG tng = new TestNG();
 tng.setVerbose(0);
 tng.setTestClasses(new Class[] { MyFactory.class});
 FactoryTest.m_count = 0;
 tng.run();
 assertEquals(FactoryTest.m_count, 4);
}

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

public static void main(String[] args) throws Exception {
  TestNG tng = new TestNG();
  String xml =
    "<suite name=\"dgf\" verbose=\"10\"><test name=\"dgf\"><classes>"
      + "<class name=\"test.dependent.MissingMethodSampleTest\"/>"
      + "</classes></test></suite>";
  System.out.println(xml);
  ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
  tng.setXmlSuites(new Parser(is).parseToList());
  tng.run();
 }
}

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

@Test
public void testParallelModeInheritanceInCommandlineMode() throws FileNotFoundException {
 SuiteXmlParser parser = new SuiteXmlParser();
 String file = "src/test/resources/1636.xml";
 XmlSuite xmlSuite = parser.parse(file, new FileInputStream(file), true);
 TestNG tng = new TestNG();
 tng.setXmlSuites(Collections.singletonList(xmlSuite));
 tng.run();
 assertThat(Github1636Sample.threads).hasSize(3);
}

代码示例来源: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
public void verifyListenerAnnotationTransformerClass() {
 MySuiteListener.triggered = false;
 MySuiteListener2.triggered = false;
 TestNG tng = new TestNG();
 tng.setVerbose(0);
 tng.addListener(new MyListenerTransformer());
 tng.setTestClasses(new Class[] {AnnotationTransformerClassSampleTest.class});
 tng.run();
 Assert.assertFalse(MySuiteListener.triggered);
 Assert.assertTrue(MySuiteListener2.triggered);
}

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

public static void main(String[] args) throws Exception {
  TestNG tng = new TestNG();
  String xml =
    "<suite name=\"dgf\" verbose=\"10\">"
      + "<test name=\"dgf\">"
      + "<classes><class name=\"test.dependent.MissingGroupSampleTest\"></class></classes>"
      + "</test>"
      + "</suite>";
  System.out.println(xml);
  ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
  tng.setXmlSuites(new Parser(is).parseToList());
  tng.run();
 }
}

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

@Test
 public void testBeforeAfterClassInvocationsWithFactory() {
  TestNG testng= new TestNG();
  testng.setTestClasses(new Class[] {XClassOrderWithFactory.class});
  TestListenerAdapter tla = new TestListenerAdapter();
  testng.addListener(tla);
  testng.setVerbose(0);
  testng.run();
  Assert.assertEquals(XClassOrderWithFactory.LOG.toString(), XClassOrderWithFactory.EXPECTED_LOG);
 }
}

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

@Test
public void testAfter() {
 TestNG tng = new TestNG();
 tng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 tng.setTestClasses(new Class[] { TestAfter1.class, TestAfter2.class });
 tng.setVerbose(0);
 tng.run();
 Assert.assertEquals(BaseAfter.m_afterCount, 1);
}

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

@BeforeMethod
public void init() {
 m_tng = new TestNG();
 m_tng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 m_tng.setVerbose(0);
 m_tng.setUseDefaultListeners(false);
}

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

@Test
  public void executionListenerAndSuiteListenerTest() {
   String suiteFile = getPathToResource("executionlistenersingletoncheck/parent.xml");
   List<XmlSuite> suites = getSuites(suiteFile);
   TestNG testng = new TestNG();
   testng.setXmlSuites(suites);
   testng.run();
   assertEquals(ExecutionListenerAndSuiteListener.getTmpString(), "INITIALIZED");
  }
}

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

@Test
public void skippedExceptionInConfigurationMethods() {
 TestListenerAdapter listener= new TestListenerAdapter();
 TestNG test= new TestNG(false);
 test.addListener((ITestNGListener)listener);
 test.setVerbose(0);
 test.setTestClasses(new Class[] {ConfigurationSkippedExceptionTest.class});
 test.run();
 List<ITestResult> confSkips= listener.getConfigurationSkips();
 List<ITestResult> testSkips= listener.getSkippedTests();
 Assert.assertEquals(testSkips.size(), 1);
 Assert.assertEquals(testSkips.get(0).getMethod().getMethodName(), "dummyTest");
 Assert.assertEquals(confSkips.size(), 1);
 Assert.assertEquals(confSkips.get(0).getMethod().getMethodName(), "configurationLevelSkipException");
}

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

@Test
public void invocationOrder() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG testng = new TestNG();
 testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 testng.setTestClasses(new Class[] {TestChild1.class, TestChild2.class});
 testng.addListener(tla);
 testng.setVerbose(0);
 testng.run();
 Assert.assertEquals(LOG.size(), 8, LOG.toString());
 int number1 = "beforeTestChild1Class".equals(LOG.get(0)) ? 1 : 2;
 int number2 = number1 == 1 ? 2 : 1;
 verifyInvocation(number1, LOG, 0);
 verifyInvocation(number2, LOG, 4);
}

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

private void runTest(XmlSuite.ParallelMode parallelMode, int expectedThreadIdCount) {
 TestNG tng = new TestNG();
 tng.setVerbose(0);
 tng.setTestClasses(new Class[] { FactorySampleTest.class});
 if (parallelMode != null) {
  tng.setParallel(parallelMode);
 }
 TestListenerAdapter tla = new TestListenerAdapter();
 tng.addListener((ITestNGListener) tla);
 B.setUp();
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 2);
 Assert.assertEquals(B.m_threadIds.size(), expectedThreadIdCount);
}

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

@Test
public void verifyConfigurationTransformer() {
 TestNG tng = new TestNG();
 tng.addListener(new ConfigurationTransformer());
 tng.setVerbose(0);
 tng.setTestClasses(new Class[] {ConfigurationSampleTest.class});
 TestListenerAdapter tla = new TestListenerAdapter();
 tng.addListener(tla);
 tng.run();
 Assert.assertEquals(ConfigurationSampleTest.getBefore(), "correct");
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@Ignore("Fails against TestNG 6.11")
public void runTestAndAssertCounters() throws Exception {
  TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
  TestNG testNG = new TestNG();
  testNG.addListener((ITestNGListener) listener);
  testNG.setTestClasses(new Class<?>[] {this.clazz});
  testNG.setVerbose(0);
  testNG.run();
  String name = this.clazz.getSimpleName();
  assertEquals("tests started for [" + name + "] ==> ", this.expectedTestStartCount, listener.testStartCount);
  assertEquals("successful tests for [" + name + "] ==> ", this.expectedTestSuccessCount, listener.testSuccessCount);
  assertEquals("failed tests for [" + name + "] ==> ", this.expectedFailureCount, listener.testFailureCount);
  assertEquals("failed configurations for [" + name + "] ==> ",
      this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount);
}

代码示例来源:origin: spring-projects/spring-framework

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((ITestNGListener) 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);
}

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

@Test(dataProvider = "dp")
public void confFailureTest(
  Class[] classesUnderTest,
  int configurationFailures,
  int configurationSkips,
  int skippedTests) {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG testng = new TestNG();
 testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 testng.setTestClasses(classesUnderTest);
 testng.addListener(tla);
 testng.setVerbose(0);
 testng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
 testng.run();
 verify(tla, configurationFailures, configurationSkips, skippedTests);
}

相关文章

TestNG类方法