org.testng.TestNG#setTestClasses ( )源码实例Demo

下面列出了org.testng.TestNG#setTestClasses ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
}
 
@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);
}
 
源代码3 项目: LevenshteinAutomaton   文件: Main.java
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    TestNG test = new TestNG();
    test.setTestClasses(new Class[]{/*PositionTest.class, StateTest.class, ParametricStateTest.class,*/ LevenshteinAutomatonTest.class});
    test.run();
   
}
 
源代码4 项目: dragonwell8_jdk   文件: ReflectionFactoryTest.java
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {ReflectionFactoryTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
/**
 * Runs the existing webapp test cases, this time against the initiated secure server instance.
 * @throws Exception
 */
@Test
public void runOtherSuitesAgainstSecureServer() throws Exception {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    // setup the credential provider
    setupCredentials();

    try {
        secureEmbeddedServer = new SecureEmbeddedServer(securePort, TestUtils.getWarPath()) {
            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }
        };
        secureEmbeddedServer.server.start();

        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[]{AdminJerseyResourceIT.class, EntityJerseyResourceIT.class,
                MetadataDiscoveryJerseyResourceIT.class,
                TypesJerseyResourceIT.class});
        testng.addListener(tla);
        testng.run();

    } finally {
        secureEmbeddedServer.server.stop();
    }

}
 
源代码6 项目: buck   文件: TestNGRunner.java
@Override
public void run() throws Throwable {
  for (String className : testClassNames) {

    Class<?> testClass = Class.forName(className);

    List<TestResult> results;
    if (!mightBeATestClass(testClass)) {
      results = Collections.emptyList();
    } else {
      results = new ArrayList<>();
      TestNG testng = new TestNG();
      testng.setUseDefaultListeners(false);
      testng.addListener(new FilteringAnnotationTransformer(results));
      testng.setTestClasses(new Class<?>[] {testClass});
      testng.addListener(new TestListener(results));
      // use default TestNG reporters ...
      testng.addListener(new SuiteHTMLReporter());
      testng.addListener((IReporter) new FailedReporter());
      testng.addListener(new XMLReporter());
      testng.addListener(new EmailableReporter());
      // ... except this replaces JUnitReportReporter ...
      testng.addListener(new JUnitReportReporterWithMethodParameters());
      // ... and we can't access TestNG verbosity, so we remove VerboseReporter
      testng.run();
    }

    writeResult(className, results);
  }
}
 
private TestNG new_TestNG_with_failure_recorder_for(Class<?>... testNGClasses) {
    TestNG testNG = new TestNG();
    testNG.setVerbose(0);
    testNG.setUseDefaultListeners(false);
    testNG.addListener(failureRecorder);

    testNG.setTestClasses(testNGClasses);
    return testNG;
}
 
源代码8 项目: atlas   文件: SecureEmbeddedServerTestBase.java
/**
 * Runs the existing webapp test cases, this time against the initiated secure server instance.
 * @throws Exception
 */
@Test
public void runOtherSuitesAgainstSecureServer() throws Exception {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    // setup the credential provider
    setupCredentials();

    try {
        secureEmbeddedServer = new SecureEmbeddedServer(
            EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS, securePort, TestUtils.getWarPath()) {
            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }
        };
        secureEmbeddedServer.server.start();

        TestListenerAdapter tla = new TestListenerAdapter();
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[]{AdminJerseyResourceIT.class, EntityJerseyResourceIT.class,
                TypesJerseyResourceIT.class});
        testng.addListener(tla);
        testng.run();

    } finally {
        secureEmbeddedServer.server.stop();
    }

}
 
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {ReflectionFactoryTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码10 项目: MDAG   文件: Main.java
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    TestNG test = new TestNG();
    test.setTestClasses(new Class[]{DAWGNodeTest.class, DAWGTest.class});
    test.run();
   
}
 
源代码11 项目: openjdk-jdk9   文件: Basic.java
@SuppressWarnings("raw_types")
public static void main(String[] args) {
    Class<?>[] testclass = {TreeTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码12 项目: jdk8u_jdk   文件: ReflectionFactoryTest.java
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {ReflectionFactoryTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码13 项目: openjdk-jdk9   文件: JImageReadTest.java
@Test(enabled=false)
@Parameters({"x"})
@SuppressWarnings("raw_types")
public static void main(@Optional String[] args) {
    Class<?>[] testclass = { JImageReadTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码14 项目: openjdk-jdk9   文件: SunMiscSignalTest.java
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {SunMiscSignalTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码15 项目: jdk8u-jdk   文件: ReflectionFactoryTest.java
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {ReflectionFactoryTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码16 项目: openjdk-jdk9   文件: ObjectStreamTest.java
@SuppressWarnings("raw_types")
@Test(enabled = false)
public static void main(String[] args) {
    Class<?>[] testclass = {ObjectStreamTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
源代码17 项目: brooklyn-server   文件: YamlsTest.java
public static void main(String[] args) {
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { YamlsTest.class });
//        testng.setVerbose(9);
        testng.run();
    }
 
源代码18 项目: test-data-supplier   文件: TestNGRunner.java
private static TestNG create(final Class<?>... testClasses) {
    TestNG result = create();
    result.setTestClasses(testClasses);
    return result;
}
 
@Test
public void runAllTckTests() throws Throwable {
    TestNG testng = new TestNG();

    ObjectFactoryImpl delegate = new ObjectFactoryImpl();
    testng.setObjectFactory((IObjectFactory) (constructor, params) -> {
        if (constructor.getDeclaringClass().equals(ReactiveStreamsCdiTck.class)) {
            return tck;
        }
        else {
            return delegate.newInstance(constructor, params);
        }
    });

    testng.setUseDefaultListeners(false);
    ResultListener resultListener = new ResultListener();
    testng.addListener((ITestNGListener) resultListener);
    testng.setTestClasses(new Class[]{ ReactiveStreamsCdiTck.class });
    testng.setMethodInterceptor(new IMethodInterceptor() {
        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
            methods.sort(Comparator.comparing(m -> m.getInstance().getClass().getName()));
            return methods;
        }
    });
    testng.run();
    int total = resultListener.success.get() + resultListener.failed.get() + resultListener.skipped.get();
    System.out.println(String.format("Ran %d tests, %d passed, %d failed, %d skipped.", total, resultListener.success.get(),
        resultListener.failed.get(), resultListener.skipped.get()));
    System.out.println("Failed tests:");
    resultListener.failures.forEach(result -> {
        System.out.println(result.getInstance().getClass().getName() + "." + result.getMethod().getMethodName());
    });
    if (resultListener.failed.get() > 0) {
        if (resultListener.lastFailure.get() != null) {
            throw resultListener.lastFailure.get();
        }
        else {
            throw new Exception("Tests failed with no exception");
        }
    }
}
 
public static void main(String[] args)
    throws Exception {
  int numArgs = args.length;
  if (!((numArgs == 6) || (numArgs == 7 && args[0].equals("--llc")))) {
    printUsage();
  }

  CustomHybridClusterIntegrationTest._enabled = true;

  int argIdx = 0;
  if (args[0].equals("--llc")) {
    CustomHybridClusterIntegrationTest._useLlc = true;
    argIdx++;
  }

  CustomHybridClusterIntegrationTest._tableName = args[argIdx++];
  File schemaFile = new File(args[argIdx++]);
  CustomHybridClusterIntegrationTest._schema = Schema.fromFile(schemaFile);
  String timeColumnName = args[argIdx++];
  CustomHybridClusterIntegrationTest._timeColumnName =
      (CustomHybridClusterIntegrationTest._schema.getFieldSpecFor(timeColumnName) != null) ? timeColumnName : null;
  File dataDir = new File(args[argIdx++]);
  Preconditions.checkState(dataDir.isDirectory());
  CustomHybridClusterIntegrationTest._dataDir = dataDir;
  CustomHybridClusterIntegrationTest._invertedIndexColumns = Arrays.asList(args[argIdx++].split(","));
  CustomHybridClusterIntegrationTest._sortedColumn = args[argIdx];

  TestListenerAdapter testListenerAdapter = new TestListenerAdapter();
  TestNG testNG = new TestNG();
  testNG.setTestClasses(new Class[]{CustomHybridClusterIntegrationTest.class});
  testNG.addListener(testListenerAdapter);
  testNG.run();

  System.out.println(testListenerAdapter.toString());
  boolean success = true;
  List<ITestResult> skippedTests = testListenerAdapter.getSkippedTests();
  if (!skippedTests.isEmpty()) {
    System.out.println("Skipped tests: " + skippedTests);
    for (ITestResult skippedTest : skippedTests) {
      System.out.println(skippedTest.getName() + ": " + skippedTest.getThrowable());
    }
    success = false;
  }
  List<ITestResult> failedTests = testListenerAdapter.getFailedTests();
  if (!failedTests.isEmpty()) {
    System.err.println("Failed tests: " + failedTests);
    for (ITestResult failedTest : failedTests) {
      System.out.println(failedTest.getName() + ": " + failedTest.getThrowable());
    }
    success = false;
  }
  if (success) {
    System.exit(0);
  } else {
    System.exit(1);
  }
}