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

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

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

TestNG.run介绍

[英]Run TestNG.
[中]运行TestNG。

代码示例

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

@Test
public void guiceTest() {
 TestNG tng = create(Guice1Test.class, Guice2Test.class);
 Guice1Test.m_object = null;
 Guice2Test.m_object = null;
 tng.run();
 assertThat(Guice1Test.m_object).isNotNull();
 assertThat(Guice2Test.m_object).isNotNull();
 assertThat(Guice1Test.m_object).isEqualTo(Guice2Test.m_object);
}

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

@Test(description = "Ensure that if a listener is present, we get test(), onSuccess()," +
    " afterMethod()")
public void listenerShouldBeCalledBeforeConfiguration() {
 TestNG tng = create(OrderedListenerSampleTest.class);
 tng.run();
 Assert.assertEquals(SimpleListener.m_list, Arrays.asList(1, 2, 3, 4));
}

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

@Test(description = "Should attach only one instance of the same @Listener class per test")
public void shouldAttachOnlyOneInstanceOfTheSameListenerClassPerTest() {
 TestNG tng = create(Derived1.class, Derived2.class);
 BaseWithListener.m_count = 0;
 tng.run();
 Assert.assertEquals(BaseWithListener.m_count, 2);
}

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

@Test
public void testSimpleDataProviderWithListenerAnnotationAndInvolvingInheritance() {
 final String prefix =
   ":" + SimpleDataProviderWithListenerAnnotationSample1.class.getName() + ".testMethod";
 TestNG tng = create(SimpleDataProviderWithListenerAnnotationSample1.class);
 tng.run();
 assertThat(LocalDataProviderListener.messages)
   .containsExactlyElementsOf(Arrays.asList("before" + prefix, "after" + prefix));
}

代码示例来源: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
  public void testExecutionTimeOfFailedConfig() throws IOException {
    ConfigListener listener = new ConfigListener();

    TestNG testNG = create(TestWithFailingConfig.class);
    testNG.addListener(listener);
    testNG.run();
    Assert.assertTrue(listener.executionTime >= TestWithFailingConfig.EXEC_TIME);
  }
}

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

@Test
 public void testGitHub1307() {
  TestNG tng = create(FactoryWithAnonymousTestsSample.class);

  InvokedMethodNameListener listener = new InvokedMethodNameListener();
  tng.addListener(listener);

  tng.run();

  assertThat(listener.getFailedMethodNames()).isEmpty();
  assertThat(listener.getSkippedMethodNames()).isEmpty();
  assertThat(listener.getSucceedMethodNames()).containsExactly("test");
 }
}

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

@Test
 public void verifyAttributeShouldStop() {
  TestNG testng = create(FailedInvocationCount2.class);
  TestListenerAdapter tla = new TestListenerAdapter();
  testng.addListener(tla);
  testng.run();

  Assert.assertEquals(tla.getPassedTests().size(), 8);
  Assert.assertEquals(tla.getFailedTests().size(), 7);
  Assert.assertEquals(tla.getSkippedTests().size(), 5);
 }
}

代码示例来源: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 testFactoryExecutionWhenNoIncludedTests() {
  XmlSuite suite = createXmlSuite("Suite");
  XmlTest test = createXmlTest(suite, "Test", ExcludedFactory.class);
  test.setExcludedGroups(Collections.singletonList(EXCLUDED_GROUP));
  TestNG tng = create(suite);

  tng.run();

  Assert.assertFalse(ExcludedFactory.factoryRan);
 }
}

代码示例来源: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 ensureGroupsPresentInInheritedMethods() {
 TestNG testng = create(ChildTest.class);
 LocalListener listener = new LocalListener();
 testng.addListener(listener);
 testng.run();
 Map<String, List<String>> expected = Maps.newHashMap();
 expected.put("parentTestMethod", Collections.singletonList(MY_GROUP));
 expected.put("childTestMethod", Collections.singletonList(MY_GROUP));
 assertThat(listener.getMapping()).containsAllEntriesOf(expected);
}

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

@Test
public void testNegativeFlowForNativeInjectionOnTestMethods() {
 Map<String, String> failures = Maps.newHashMap();
 failures.put(
   "m1", "Cannot inject @Test annotated Method [m1] with [interface org.testng.ITestResult].");
 failures.put("m2", "Cannot inject @Test annotated Method [m2] with [int].");
 TestNG testng = create(NegativeNativeInjectionTestSample.class);
 Github1649TestListener listener = new Github1649TestListener();
 testng.addListener(listener);
 testng.run();
 assertThat(listener.failures).containsAllEntriesOf(failures);
}

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

@Test
public void testDuplicationFunctionality() {
 XmlSuite suite = createXmlSuite("suite", "test", TestClassSample.class);
 TestNG testng = create(suite);
 MethodMultiplyingInterceptor tla = new MethodMultiplyingInterceptor();
 testng.addListener(tla);
 testng.run();
 int expected = tla.getMultiplyCount() + tla.getOriginalMethodCount();
 assertThat(tla.getPassedTests().size()).isEqualTo(expected);
}

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

private ITestClass runTestWithDefaultMethods() {
 TestNG tng = create(TestA.class);
 TestClassListener listener = new TestClassListener();
 tng.addListener(listener);
 tng.run();
 return listener.testClass;
}

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

@Test
public void shouldIncludeFailedMethodsFromBaseClass() throws IOException {
 Path tempDirectory = Files.createTempDirectory("temp-testng-");
 XmlSuite suite = createXmlSuite(suiteName, "TmpTest", Child.class);
 TestNG tng = create(tempDirectory, suite);
 tng.addListener(new FailedReporter());
 tng.run();
 verify(tempDirectory, suiteName, expected);
}

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

@Test(description = "Test methods with expected exceptions should show up as pass" +
    " in IInvokedMethodListener's afterInvocation method")
public void testMethodsWithExpectedExceptionsShouldShowUpAsPass() {
 TestNG tng = create(Sample2.class);
 Sample2.Sample2InvokedMethodListener l = new Sample2().new Sample2InvokedMethodListener();
 tng.addListener((ITestNGListener) l);
 tng.run();
 Assert.assertTrue(l.isSuccess);
}

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

private void triggerTest(String packageName, boolean applyGroupSelectionAtTest) {
 final XmlSuite suite = createXmlSuite("1297_suite");
 final XmlTest xmlTest = createXmlTestWithPackages(suite, "1297_test", packageName);
 if (applyGroupSelectionAtTest) {
  createXmlGroups(xmlTest, "run");
 } else {
  createXmlGroups(suite, "run");
 }
 TestNG tng = create(mTempDirectory.toPath(), suite);
 tng.setUseDefaultListeners(true);
 tng.run();
}

代码示例来源: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);
}

相关文章

TestNG类方法