Search in sources :

Example 6 with TestNG

use of org.testng.TestNG in project mockito by mockito.

the class TestNGShouldFailWhenMockitoListenerFailsTest method new_TestNG_with_failure_recorder_for.

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;
}
Also used : TestNG(org.testng.TestNG)

Example 7 with TestNG

use of org.testng.TestNG in project jdk8u_jdk by JetBrains.

the class ReflectionFactoryTest method main.

// Main can be used to run the tests from the command line with only testng.jar.
@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();
}
Also used : TestNG(org.testng.TestNG) BeforeClass(org.testng.annotations.BeforeClass) Test(org.testng.annotations.Test)

Example 8 with TestNG

use of org.testng.TestNG in project spring-framework by spring-projects.

the class ClassLevelDirtiesContextTestNGTests method runTestClassAndAssertStats.

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);
}
Also used : TrackingTestNGTestListener(org.springframework.test.context.testng.TrackingTestNGTestListener) TestNG(org.testng.TestNG)

Example 9 with TestNG

use of org.testng.TestNG in project gradle by gradle.

the class TestNGTestClassProcessor method runTests.

private void runTests() {
    TestNG testNg = new TestNG();
    testNg.setOutputDirectory(testReportDir.getAbsolutePath());
    testNg.setDefaultSuiteName(options.getDefaultSuiteName());
    testNg.setDefaultTestName(options.getDefaultTestName());
    if (options.getParallel() != null) {
        testNg.setParallel(options.getParallel());
    }
    if (options.getThreadCount() > 0) {
        testNg.setThreadCount(options.getThreadCount());
    }
    invokeVerifiedMethod(testNg, "setConfigFailurePolicy", String.class, options.getConfigFailurePolicy(), DEFAULT_CONFIG_FAILURE_POLICY);
    invokeVerifiedMethod(testNg, "setPreserveOrder", boolean.class, options.getPreserveOrder(), false);
    invokeVerifiedMethod(testNg, "setGroupByInstances", boolean.class, options.getGroupByInstances(), false);
    testNg.setUseDefaultListeners(options.getUseDefaultListeners());
    testNg.setVerbose(0);
    testNg.setGroups(CollectionUtils.join(",", options.getIncludeGroups()));
    testNg.setExcludedGroups(CollectionUtils.join(",", options.getExcludeGroups()));
    // this way, custom listeners are more powerful and, for example, they can change test status.
    for (String listenerClass : options.getListeners()) {
        try {
            testNg.addListener(applicationClassLoader.loadClass(listenerClass).newInstance());
        } catch (Throwable e) {
            throw new GradleException(String.format("Could not add a test listener with class '%s'.", listenerClass), e);
        }
    }
    if (!options.getIncludedTests().isEmpty() || !options.getIncludedTestsCommandLine().isEmpty()) {
        testNg.addListener(new SelectedTestsFilter(options.getIncludedTests(), options.getIncludedTestsCommandLine()));
    }
    if (!suiteFiles.isEmpty()) {
        testNg.setTestSuites(GFileUtils.toPaths(suiteFiles));
    } else {
        testNg.setTestClasses(testClasses.toArray(new Class[0]));
    }
    testNg.addListener((Object) adaptListener(new TestNGTestResultProcessorAdapter(resultProcessor, idGenerator, clock)));
    testNg.run();
}
Also used : TestNG(org.testng.TestNG) GradleException(org.gradle.api.GradleException)

Example 10 with TestNG

use of org.testng.TestNG in project pinot by linkedin.

the class HybridScanBasedCommandLineTestRunner method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        usage();
    }
    int expectedArgsLen = 5;
    int ix = 0;
    // Parse optional arguments first.
    while (args[ix].startsWith("-")) {
        if (args[ix].equals("--record")) {
            CustomHybridClusterScanComparisonIntegrationTest._recordScanResponses = true;
        } else if (args[ix].equals("--llc")) {
            CustomHybridClusterScanComparisonIntegrationTest._useLlc = true;
        } else {
            usage();
        }
        ix++;
        expectedArgsLen++;
    }
    if (args.length != expectedArgsLen) {
        usage();
    }
    final String tableName = args[ix++];
    final String schemaFilePath = args[ix++];
    // we expect a dir called 'avro-files' and files called 'queries.txt' and 'scan-responses.txt' in here
    final String segQueryDirPath = args[ix++];
    final String invIndexCols = args[ix++];
    final String sortedCol = args[ix++];
    CustomHybridClusterScanComparisonIntegrationTest.setParams(tableName, schemaFilePath, segQueryDirPath, invIndexCols, sortedCol);
    TestListenerAdapter tla = new TestListenerAdapter();
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] { CustomHybridClusterScanComparisonIntegrationTest.class });
    testng.addListener(tla);
    testng.run();
    System.out.println("Passed tests: " + tla.getPassedTests());
    if (!tla.getSkippedTests().isEmpty()) {
        System.out.println("Skipped tests: " + tla.getSkippedTests());
    }
    System.out.println(tla.toString());
    if (!tla.getFailedTests().isEmpty()) {
        System.err.println("Failed tests:" + tla.getFailedTests());
        System.exit(1);
    }
    System.exit(0);
}
Also used : TestNG(org.testng.TestNG) TestListenerAdapter(org.testng.TestListenerAdapter)

Aggregations

TestNG (org.testng.TestNG)18 Test (org.testng.annotations.Test)5 TrackingTestNGTestListener (org.springframework.test.context.testng.TrackingTestNGTestListener)2 TestListenerAdapter (org.testng.TestListenerAdapter)2 BeforeClass (org.testng.annotations.BeforeClass)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 GradleException (org.gradle.api.GradleException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 ITestListener (org.testng.ITestListener)1 SimpleBaseTest (samples.testng.SimpleBaseTest)1