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

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

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

TestNG.setTestClasses介绍

[英]Set the test classes to be run by this TestNG object. This method will create a dummy suite that will wrap these classes called "Command Line Test".

If used together with threadCount, parallel, groups, excludedGroups than this one must be set first.
[中]设置此TestNG对象要运行的测试类。该方法将创建一个虚拟套件,该套件将封装这些类,称为“命令行测试”。
如果与threadCount、parallel、groups、excludedGroups一起使用,则必须先设置此选项。

代码示例

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

private void runTest(Class cls, List<Integer> list, List<Integer> expected) {
   m_testNg.setTestClasses(new Class[] {
     cls
   });
   m_testNg.run();
   Assert.assertEquals(list, expected);
 }
}

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

@Test
 public void verify() {
  TestNG tng = create();
  tng.setTestClasses(new Class[] { test.testng317.ClassB.class, test.testng317.ClassA.class });
  tng.run();

  System.out.println("Methods:" + m_methods.size());
 }
}

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

@Test
public void noMethodsShouldRun() {
 TestNG tng = create();
 tng.setTestClasses(new Class[] { FooTest.class });
 testNullInterceptor(tng);
}

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

@Test(description = "GITHUB-1700")
 public void testMethod() {
  TestNG tng = create();
  tng.setTestClasses(new Class[] {ChildClassTestSample1.class, ChildClassTestSample2.class});
  tng.run();
  assertThat(BaseClassSample.messages)
    .containsOnly(
      ChildClassTestSample2.class.getCanonicalName() + ".setup()",
      ChildClassTestSample2.class.getCanonicalName() + ".test2()");
 }
}

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

@Test(description = "Second test method")
public void verifyIncludedExcludedCount2() {
 m_tng.setTestClasses(new Class[] {IncludedExcludedSampleTest.class});
 m_tng.addListener((ITestNGListener)
   new MyReporter(
     new String[] {
       "beforeSuite", "beforeTest", "beforeTestClass",
       "beforeTestMethod", "test1", "beforeTestMethod", "test3"
      },
     new String[] { "test2"}));
 m_tng.run();
}

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

@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(description = "First test method")
public void verifyIncludedExcludedCount1() {
 m_tng.setTestClasses(new Class[] {IncludedExcludedSampleTest.class});
 m_tng.setGroups("a");
 m_tng.addListener((ITestNGListener)
   new MyReporter(new String[] { "test3" }, new String[] { "test1", "test2"}));
 m_tng.run();
}

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

protected static TestNG run(TestNG result, Class<?>[] classes, String outputDir) {
 result.setVerbose(0);
 result.setOutputDirectory(outputDir);
 result.setTestClasses(classes);
 result.run();
 return result;
}

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

@Test(enabled = false)
public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) {
 TestNG tng = create();
 tng.setTestClasses(new Class[] { Sample.class });
 TestListenerAdapter tla = new TestListenerAdapter();
 tng.addListener(tla);
 tng.run();
 Assert.assertEquals(xmlTest.getName(), "Injection");
 Assert.assertEquals(tla.getPassedTests().size(), 1);
 Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f");
}

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

private static void run(Class[] classes, IInvokedMethodListener l) {
 TestNG tng = create();
 tng.setTestClasses(classes);
 tng.addListener((ITestNGListener) l);
 tng.run();
}

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

@Test
public void verifyFactoryTransformer() {
 TestNG tng = create();
 tng.addListener(new FactoryTransformer());
 tng.setTestClasses(new Class[] {AnnotationTransformerFactorySampleTest.class});
 TestListenerAdapter tla = new TestListenerAdapter();
 tng.addListener(tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 1);
}

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

@Test
public void verifyDataProviderTransformer() {
 TestNG tng = create();
 tng.addListener(new DataProviderTransformer());
 tng.setTestClasses(new Class[] {AnnotationTransformerDataProviderSampleTest.class});
 TestListenerAdapter tla = new TestListenerAdapter();
 tng.addListener(tla);
 tng.run();
 Assert.assertEquals(tla.getPassedTests().size(), 1);
}

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

@Test
public void withoutAlwaysRunAfter() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG testng = create();
 testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 testng.setTestClasses(new Class[] {AlwaysRunAfter2.class});
 testng.addListener(tla);
 testng.run();
 assertTrue(AlwaysRunAfter2.success(), "afterTestMethod should not have run");
}

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

@Test
public void withAlwaysRunAfter() {
 TestListenerAdapter tla = new TestListenerAdapter();
 TestNG testng = create();
 testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory());
 testng.setTestClasses(new Class[] {AlwaysRunAfter1.class});
 testng.addListener(tla);
 testng.run();
 assertTrue(AlwaysRunAfter1.success(), "afterTestMethod should have run");
}

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

相关文章

TestNG类方法