@Test(description = "Make sure that listeners defined in testng.xml are invoked") public void listenerInXmlShouldBeInvoked() { TestNG tng = create(); tng.setTestSuites(Arrays.asList(getPathToResource("listener-in-xml.xml"))); LListener.invoked = false; tng.run(); Assert.assertTrue(LListener.invoked); } }
@Test(priority = 2) public void verifyWithListener() { TestNG testNG = create(); testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284_withlistener.xml"))); testNG.run(); Assert.assertEquals(testNG.getStatus(), 0); }
@Test(priority = 1) public void verifyWithoutListener() { TestNG testNG = create(); testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284_nolistener.xml"))); testNG.run(); Assert.assertEquals(testNG.getStatus(), 0); }
@Test(priority = 3) public void verifyWithChildSuite() { TestNG testNG = create(); testNG.setTestSuites(Collections.singletonList(getPathToResource("test/listeners/github1284/github1284.xml"))); testNG.run(); Assert.assertEquals(testNG.getStatus(), 0); }
@Test public void ensureThatParallelismAndThreadCountAreRallied() { TestNG testng = create(); testng.setTestSuites(Collections.singletonList("src/test/resources/987.xml")); testng.setThreadCount(2); testng.setParallel(XmlSuite.ParallelMode.METHODS); testng.run(); assertThat(Issue987TestSample.maps).hasSize(2); assertThat(Issue987TestSample.maps.values()).contains("method2", "method1"); }
@Test(description = "GITHUB-1834") public void ensureDependenciesDefinedInSuiteAreHonored() throws IOException { File file = File.createTempFile("1834", ".xml"); Files.writeFile(asSuite(), file); TestNG testng = create(); testng.setTestSuites(Collections.singletonList(file.getAbsolutePath())); OutputGatheringListener listener = new OutputGatheringListener(); testng.addListener(listener); testng.run(); assertThat(listener.getConsoleLogs()).containsExactly("Uncached", "Cached"); }
@Test public void testMethod() { String suite = "src/test/resources/parametertest/1417.xml"; TestNG testNG = new TestNG(); testNG.setTestSuites(Collections.singletonList(suite)); testNG.run(); Assert.assertFalse(testNG.hasFailure()); Assert.assertFalse(testNG.hasSkip()); Assert.assertEquals(AnotherTestClassSample.getInstance().getBrowsername(), "chrome"); List<String> actual = YetAnotherTestClassSample.getInstance().getBrowsers(); Assert.assertEquals(actual.size(), 2); Assert.assertEquals(actual, Arrays.asList("safari", "safari")); } }
@Test(description = "Checks to make sure parameters are inherited and overridden properly") public void parameterInheritanceAndOverriding() { TestNG tng = create(); tng.setTestSuites(Arrays.asList(getPathToResource("parametertest/parent-suite.xml"))); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 3); } }
/** * Child suites and tests within different suites have same names */ @Test public void check() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); String testngXmlPath = getPathToResource("checksuitesinitialization/parent-suite.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener(tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 4); }
/** * Simple suite with no two tests with same name */ @Test public void checkNoError() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); String testngXmlPath = getPathToResource("sanitycheck/test2.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 2); }
/** * Child suites and tests within different suites have same names */ @Test(enabled = false) public void checkNoErrorWtihChildSuites() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); String testngXmlPath = getPathToResource("sanitycheck/test-b.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 4); }
/** * Child suites have different names */ @Test public void checkChildSuites() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); String testngXmlPath = getPathToResource("sanitycheck/test-s-b.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 4); }
@Test(description="Ensure that TestNG stops without running any tests if some class" + " included in suite is missing") public void handleInvalidSuites() { TestListenerAdapter tla = new TestListenerAdapter(); try { TestNG tng = create(); String testngXmlPath = getPathToResource("suite1.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); } catch (TestNGException ex) { Assert.assertEquals(tla.getPassedTests().size(), 0); } }
@Test public void checkWithoutChildSuites() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); tng.setTestNames(Collections.singletonList("testGroup2")); tng.setTestSuites(Collections.singletonList(getPathToResource("testnames/upstream-suite.xml"))); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getFailedTests().size(), 0); Assert.assertEquals(tla.getPassedTests().size(), 1); Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "sampleOutputTest2"); } }
@Test public void xmlXmlSuite() { TestNG tng = create(); tng.setTestSuites(Collections.singletonList(getPathToResource("methodselector-in-xml.xml"))); tng.addListener((ITestNGListener) m_tla); tng.run(); validate(new String[] { "test2" }); }
private void runSuite(String suitePath) { TestListenerAdapter tla = new TestListenerAdapter(); boolean exceptionRaised = false; try { TestNG tng = create(); String testngXmlPath = getPathToResource(suitePath); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); } catch (TestNGException ex) { exceptionRaised = true; Assert.assertEquals(tla.getPassedTests().size(), 0); Assert.assertEquals(tla.getFailedTests().size(), 0); } Assert.assertTrue(exceptionRaised); }
@Test public void testMultipleInterceptorsWithPreserveOrder() { TestNG tng = create(); tng.setTestSuites(Collections.singletonList( getPathToResource("/methodinterceptors/multipleinterceptors/multiple-interceptors.xml"))); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getDescription(), "abc"); } }
@Test(description = "Number of threads (2) is less than number of suites (3)") public void suitesShouldRunInParallel3() { final int SUITE_THREAD_POOL_SIZE = 2; TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); tng.setSuiteThreadPoolSize(SUITE_THREAD_POOL_SIZE); tng.setTestSuites(Collections.singletonList(getPathToResource("suite-parallel-0.xml"))); tng.addListener((ITestNGListener) tla); BaseThreadTest.initThreadLog(); tng.run(); //Shouldn't not deadlock Assert.assertEquals(BaseThreadTest.getThreadCount(), SUITE_THREAD_POOL_SIZE); }
/** * Child suites have same names */ @Test public void checkChildSuitesFails() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); String testngXmlPath = getPathToResource("sanitycheck/test-s-a.xml"); tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); Assert.assertEquals(tla.getTestContexts().get(0).getSuite().getName(), "SanityCheck suites"); Assert.assertEquals(tla.getTestContexts().get(1).getSuite().getName(), "SanityCheck suites"); Assert.assertEquals(tla.getTestContexts().get(2).getSuite().getName(), "SanityCheck suites (0)"); Assert.assertEquals(tla.getTestContexts().get(3).getSuite().getName(), "SanityCheck suites (0)"); }
private void runTest(int suiteThreadPoolSize, int expectedThreadCount, int expectedSuiteCount, Boolean randomizeSuites, List<String> paths) { TestListenerAdapter tla = new TestListenerAdapter(); TestNG tng = create(); tng.setSuiteThreadPoolSize(suiteThreadPoolSize); tng.setTestSuites(paths); tng.addListener((ITestNGListener) tla); if (null != randomizeSuites) { tng.setRandomizeSuites(randomizeSuites); } BaseThreadTest.initThreadLog(); tng.run(); Assert.assertEquals(BaseThreadTest.getThreadCount(), expectedThreadCount, "Thread count expected:" + expectedThreadCount + " actual:" + BaseThreadTest.getThreadCount()); Assert.assertEquals(BaseThreadTest.getSuitesMap().keySet().size(), expectedSuiteCount); }