Java Code Examples for org.testng.TestNG#setTestClasses()

The following examples show how to use org.testng.TestNG#setTestClasses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecureEmbeddedServerTestBase.java    From atlas with Apache License 2.0 7 votes vote down vote up
/**
 * 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();
    }

}
 
Example 2
Source File: ClassLevelDirtiesContextTestNGTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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);
}
 
Example 3
Source File: SecureEmbeddedServerTestBase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }

}
 
Example 4
Source File: FailingBeforeAndAfterMethodsTestNGTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example 5
Source File: ObjectStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: ReflectionFactoryTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: SunMiscSignalTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: JImageReadTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: ReflectionFactoryTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 10
Source File: Basic.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("raw_types")
public static void main(String[] args) {
    Class<?>[] testclass = {TreeTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
Example 11
Source File: Main.java    From MDAG with Apache License 2.0 5 votes vote down vote up
/**
 * @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();
   
}
 
Example 12
Source File: ReflectionFactoryTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 13
Source File: TestNGShouldFailWhenMockitoListenerFailsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: TestNGRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example 15
Source File: ReflectionFactoryTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example 16
Source File: Main.java    From LevenshteinAutomaton with Apache License 2.0 5 votes vote down vote up
/**
 * @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();
   
}
 
Example 17
Source File: HybridClusterIntegrationTestCommandLineRunner.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
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);
  }
}
 
Example 18
Source File: ReactiveStreamsArquillianTck.java    From microprofile-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@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");
        }
    }
}
 
Example 19
Source File: TestNGRunner.java    From test-data-supplier with Apache License 2.0 4 votes vote down vote up
private static TestNG create(final Class<?>... testClasses) {
    TestNG result = create();
    result.setTestClasses(testClasses);
    return result;
}
 
Example 20
Source File: YamlsTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
        TestNG testng = new TestNG();
        testng.setTestClasses(new Class[] { YamlsTest.class });
//        testng.setVerbose(9);
        testng.run();
    }