@Test public void shouldNotUseThreadsIfNotUsingParallel() { TestNG tng = create(DataProviderThreadPoolSizeSampleTest.class); tng.setGroups("sequential"); tng.run(); Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 1); }
@Test public void shouldUseDefaultDataProviderThreadCount() { TestNG tng = create(DataProviderThreadPoolSizeSampleTest.class); tng.setGroups("parallel"); tng.run(); Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 10); }
@Test public void shouldUseSpecifiedDataProviderThreadCount() { TestNG tng = create(DataProviderThreadPoolSizeSampleTest.class); tng.setGroups("parallel"); tng.setDataProviderThreadCount(3); tng.run(); Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 3); } }
@Test(dataProvider = "getTestData") public void testBeforeSuiteInjection(Class clazz, String methodName, String expected) { TestNG tng = create(clazz); InjectionResultHolder holder = new InjectionResultHolder(); tng.addListener(holder); tng.setGroups("test"); tng.run(); Assert.assertTrue(holder.getErrorMessage().contains(expected + methodName)); }
@Test(dataProvider = "dp") public void verify(int number, String passed) { TestNG tng = create(TestContextSample.class); tng.setGroups(String.valueOf(number)); InvokedMethodNameListener listener = new InvokedMethodNameListener(); tng.addListener(listener); tng.run(); assertThat(listener.getSucceedMethodNames()).hasSize(1); assertThat(listener.getSucceedMethodNames().get(0)) .matches(passed + "\\(\\[foo(,foo){" + (number - 1) + "}?\\]\\)"); assertThat(listener.getFailedMethodNames()).isEmpty(); } }
@Test(description = "First test method") public void verifyIncludedExcludedCount1() { m_tng.setTestClasses(new Class[] {IncludedExcludedSampleTest.class}); m_tng.setGroups("a"); m_tng.addListener((ITestNGListener) new MyReporter(new String[] { "test3" }, new String[] { "test1", "test2"})); m_tng.run(); }
private void runTest(String group, String excludedGroups, List<String> methods) { XmlSuite s = createXmlSuite(getClass().getName()); createXmlTest(s, "Test", OverrideSampleTest.class.getName()); TestNG tng = create(); if (group != null) tng.setGroups(group); if (excludedGroups != null) tng.setExcludedGroups(excludedGroups); tng.setXmlSuites(Collections.singletonList(s)); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); assertTestResultsEqual(tla.getPassedTests(), methods); }
private void runTest(String include, String exclude) { File f = Utils.createTempFile( "<suite name=\"S\">" + " <test name=\"T\">" + " <classes>" + " <class name=\"test.override.OverrideSampleTest\" />" + " </classes>" + " </test>" + "</suite>" ); TestNG tng = create(); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); if (include != null) tng.setGroups(include); if (exclude != null) tng.setExcludedGroups(exclude); tng.setTestSuites(Collections.singletonList(f.getAbsolutePath())); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 1); }
@Test public void withoutAlwaysRunBefore() { TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = create(); testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory()); testng.setTestClasses(new Class[] {AlwaysRunBefore1.class}); testng.setGroups("A"); testng.addListener(tla); testng.run(); assertTrue(AlwaysRunBefore1.success(), "before alwaysRun methods should have been run"); } }
setGroups(cla.groups); setExcludedGroups(cla.excludedGroups); setTestJar(cla.testJar);
suite.setExcludedGroups(excludedSuiteGroups); } else { tng.setGroups(Joiner.on(',').join(suiteGroups)); tng.setExcludedGroups(Joiner.on(',').join(excludedSuiteGroups));
setGroups(cla.groups); setExcludedGroups(cla.excludedGroups); setTestJar(cla.testJar);
private void applyConfig(TestNG core, TestNGConfiguration config) { core.setExcludedGroups(config.getExcludedGroups()); core.setGroups(config.getGroups()); if (config.getListeners() != null) { for (Object listener : config.getListeners()) { core.addListener(listener); } } }