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

The following examples show how to use org.testng.TestNG#run() . 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: 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 2
Source File: ElectPrimaryTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        int count = -1;
        Stopwatch sw = Stopwatch.createStarted();
        while (++count<100) {
            log.info("new test run\n\n\nTEST RUN "+count+"\n");
            
//            ElectPrimaryTest t = new ElectPrimaryTest();
//            t.setUp();
//            t.testFireCausesPromoteDemote();
//            t.tearDown();
            
            TestNG testNG = new TestNG();
            testNG.setTestClasses(new Class[] { ElectPrimaryTest.class });
            testNG.addListener((ITestNGListener)new LoggingVerboseReporter());
            FailedReporter failedReporter = new FailedReporter();
            testNG.addListener((ITestNGListener)failedReporter);
            testNG.run();
            if (!failedReporter.getFailedTests().isEmpty()) {
                log.error("Failures: "+failedReporter.getFailedTests());
                System.exit(1);
            }
        }
        log.info("\n\nCompleted "+count+" runs in "+Duration.of(sw));
    }
 
Example 3
Source File: ClassLevelDirtiesContextTestNGTests.java    From spring4-understanding with Apache License 2.0 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(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 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: ClassLevelDirtiesContextTestNGTests.java    From java-technology-stack 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 6
Source File: AllureTestListenerSuiteNameTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    resultsDir = folder.newFolder();
    AllureResultsUtils.setResultsDirectory(resultsDir);

    List<String> suites = new ArrayList<>();
    URL resource = getClass().getClassLoader().getResource("suite3.xml");
    assertNotNull("could not find suite3.xml", resource);

    //noinspection ConstantConditions
    suites.add(resource.getFile());

    TestNG testNG = new TestNG();
    testNG.setTestSuites(suites);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
Example 7
Source File: AllureTestListenerGroupsTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test // see https://github.com/allure-framework/allure-core/issues/880
public void reportContainsTestForGroups() {
    // GIVEN: an TestNG suite with groups 
    TestNG testNG = new TestNG(false);
    testNG.setTestSuites(singletonList(getClass().getClassLoader().getResource("suite-groups.xml").getFile()));

    // WHEN: executing
    testNG.run();

    // THEN: report only contains results for included groups
    List<File> files = listTestSuiteFiles(resultsDir);
    assertThat(files, hasSize(1));
    File file = files.get(0);
    TestSuiteResult result = unmarshal(file, TestSuiteResult.class);
    assertThat(result.getTestCases(), hasSize(2));
    List<String> status = new ArrayList<>();
    for (TestCaseResult test : result.getTestCases()) {
        status.add(test.getName() + ":" + test.getStatus());
    }
    assertThat(status, containsInAnyOrder("inactiveIncludedTest:PENDING", "activeIncludedTest:PASSED"));
}
 
Example 8
Source File: TestNgExecutor.java    From JGiven with Apache License 2.0 6 votes vote down vote up
@Override
public TestExecutionResult execute( Class<?> testClass, String testMethod ) {
    TestNgExecutionResult result = new TestNgExecutionResult();
    ScenarioTestListenerAdapter testListenerAdapter = new ScenarioTestListenerAdapter();
    TestNG testng = new TestNG();
    testng.setTestClasses( new Class<?>[] { testClass } );
    if( testMethod != null ) {
        methodName = testMethod;
        testng.addMethodSelector( MethodSelector.class.getName(), 10 );
    }
    testng.addListener( testListenerAdapter );
    Config.config().setReportEnabled( false );
    testng.run();
    Config.config().setReportEnabled( true );
    result.reportModel = testListenerAdapter.reportModel;
    result.testResults = testListenerAdapter.testResults;
    return result;
}
 
Example 9
Source File: AllureTestListenerXmlValidationTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
    resultsDir = Files.createTempDirectory(ALLURE_RESULTS);
    AllureResultsUtils.setResultsDirectory(resultsDir.toFile());

    TestNG testNG = new TestNG();
    testNG.setDefaultSuiteName(DEFAULT_SUITE_NAME);
    testNG.setTestClasses(new Class[]{TestDataClass.class});
    testNG.setUseDefaultListeners(false);

    testNG.run();
}
 
Example 10
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 11
Source File: InfoTest.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 = {InfoTest.class};
    TestNG testng = new TestNG();
    testng.setTestClasses(testclass);
    testng.run();
}
 
Example 12
Source File: TestNGMainClass.java    From journaldev with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	TestNG testSuite = new TestNG();
	testSuite.setTestClasses(new Class[] { Test5.class });
	testSuite.addListener(new Test5SuiteListener());
	testSuite.setDefaultSuiteName("My Test Suite");
	testSuite.setDefaultTestName("My Test");
	testSuite.setOutputDirectory("/Users/pankaj/temp/testng-output");
	testSuite.run();
}
 
Example 13
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 14
Source File: AllureTestListenerConfigMethodsTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {
    resultsDir = Files.createTempDirectory(ALLURE_RESULTS);
    AllureResultsUtils.setResultsDirectory(resultsDir.toFile());

    List<XmlSuite> suites = new ArrayList<>();
    for (ConfigMethodType type : ConfigMethodType.values()) {
        suites.add(createSuite(type.getTitle()));
    }

    TestNG testNG = new TestNG();
    testNG.setXmlSuites(suites);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
Example 15
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run testng suites {suites}")
private AllureResults runTestNgSuites(final Consumer<TestNG> configurer,
                                      final String... suites) {
    final ClassLoader classLoader = getClass().getClassLoader();
    List<String> suiteFiles = Arrays.stream(suites)
            .map(classLoader::getResource)
            .filter(Objects::nonNull)
            .map(URL::getFile)
            .collect(Collectors.toList());

    assertThat(suites)
            .as("Cannot find all suite xml files")
            .hasSameSizeAs(suiteFiles);

    final AllureResultsWriterStub results = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(results);
    final AllureTestNg adapter = new AllureTestNg(lifecycle);
    final TestNG testNg = new TestNG(false);
    testNg.addListener((ITestNGListener) adapter);
    testNg.setTestSuites(suiteFiles);

    configurer.accept(testNg);

    final AllureLifecycle cached = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        testNg.run();
    } finally {
        Allure.setLifecycle(cached);
        StepsAspects.setLifecycle(cached);
        AttachmentsAspects.setLifecycle(cached);
    }
    return results;
}
 
Example 16
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 17
Source File: TestNGShouldFailWhenMockitoListenerFailsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void report_failure_on_incorrect_stubbing_syntax_with_matchers_in_test_methods() throws Exception {
    TestNG testNG = new_TestNG_with_failure_recorder_for(FailingOnPurposeBecauseIncorrectStubbingSyntax.class);

    testNG.run();

    assertTrue(testNG.hasFailure());
    assertThat(failureRecorder.lastThrowable()).isInstanceOf(InvalidUseOfMatchersException.class);
}
 
Example 18
Source File: TestNGShouldFailWhenMockitoListenerFailsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void report_failure_on_incorrect_annotation_usage() throws Throwable {
    TestNG testNG = new_TestNG_with_failure_recorder_for(FailingOnPurposeBecauseIncorrectAnnotationUsage.class);

    testNG.run();

    assertTrue(testNG.hasFailure());
    assertThat(failureRecorder.lastThrowable()).isInstanceOf(MockitoException.class);
}
 
Example 19
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 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();
    }