/** * Sets the test suite to run using the given URI reference. Three types of * references are supported: * <ul> * <li>A file system reference</li> * <li>A file: URI</li> * <li>A jar: URI</li> * </ul> * * @param driver * The main TestNG driver. * @param ets * A URI referring to a suite definition. */ private void setTestSuites(TestNG driver, URI ets) { if (ets.getScheme().equalsIgnoreCase("jar")) { // jar:{url}!/{entry} String[] jarPath = ets.getSchemeSpecificPart().split("!"); File jarFile = new File(URI.create(jarPath[0])); driver.setTestJar(jarFile.getAbsolutePath()); driver.setXmlPathInJar(jarPath[1].substring(1)); } else { List<String> testSuites = new ArrayList<String>(); File tngFile = new File(ets); if (tngFile.exists()) { LOGR.log(Level.CONFIG, "Using TestNG config file {0}", tngFile.getAbsolutePath()); testSuites.add(tngFile.getAbsolutePath()); } else { throw new IllegalArgumentException("A valid TestNG config file reference is required."); } driver.setTestSuites(testSuites); } }
/** * * @param testNG testNG instance * @param existingListeners existing listeners list (TestListeners/SuiteListeners/ReportListeners/... list) * @param listenerClassName listener canonical name */ private void addListener( TestNG testNG, List<?> existingListeners, String listenerClassName ) { Class<?> listenerClass; try { listenerClass = Class.forName(listenerClassName); if (!isListenerAlreadyAttached(existingListeners, listenerClass)) { Object listener = listenerClass.newInstance(); testNG.addListener(listener); logger.info("Successfully attached listener \"" + listenerClassName + "\"."); } else { logger.info("Skip attaching listener \"" + listenerClassName + "\". It's already attached!"); } } catch (Exception e) { logger.error("Error attaching listener: \"" + listenerClassName + "\".", e); } }
@Test public void verifyHappyPath() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("testPassed"); testNG.run(); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); ITestResult result = tla.getPassedTests().get(0); assertNull(UnitTestArtifact.getCaptureState(result), "Artifact provider capture state should be 'null'"); assertNull(UnitTestCapture.getArtifactPath(result), "Artifact capture should not have been requested"); }
@Test public void verifyCaptureOnFailure() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("testFailed"); testNG.run(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); ITestResult result = tla.getFailedTests().get(0); assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state"); assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present"); }
@Test public void verifyCanNotCapture() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("canNotCapture"); testNG.run(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); ITestResult result = tla.getFailedTests().get(0); assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAN_NOT_CAPTURE, "Incorrect artifact provider capture state"); assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present"); }
@Test public void verifyWillNotCapture() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("willNotCapture"); testNG.run(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); ITestResult result = tla.getFailedTests().get(0); assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_FAILED, "Incorrect artifact provider capture state"); assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present"); }
@Test public void verifyOnDemandCapture() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("onDemandCapture"); testNG.run(); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); ITestResult result = tla.getPassedTests().get(0); assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state"); assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present"); }
@Test public void testAttributeHandOff() { ExecutionFlowController efc = new ExecutionFlowController(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{HappyPathClass.class}); testNG.addListener((ITestNGListener) efc); testNG.addListener((ITestNGListener) tla); testNG.run(); assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure"); assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure"); assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(HappyPathClass.fromBefore, HappyPathClass.VALUE, "Incorrect [before] value"); assertEquals(HappyPathClass.fromMethod, HappyPathClass.VALUE, "Incorrect [method] value"); assertEquals(HappyPathClass.fromAfter, HappyPathClass.VALUE, "Incorrect [after] value"); }
@Test public void testSkipFromMethod() { ExecutionFlowController efc = new ExecutionFlowController(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{SkipFromMethod.class}); testNG.addListener((ITestNGListener) efc); testNG.addListener((ITestNGListener) tla); testNG.run(); assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure"); assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure"); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count"); assertEquals(tla.getSkippedTests().get(0).getName(), "testMethod", "Incorrect skipped test name"); assertEquals(SkipFromMethod.fromBefore, SkipFromMethod.VALUE, "Incorrect [before] value"); assertEquals(SkipFromMethod.fromMethod, SkipFromMethod.VALUE, "Incorrect [method] value"); assertEquals(SkipFromMethod.fromAfter, SkipFromMethod.VALUE, "Incorrect [after] value"); }
@Override public void run() { try { TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = new TestNG(); testng.setTestClasses(new Class[] { HybridTest.class }); //testng.settes testng.addListener(tla); testng.run(); }catch (Exception e) { e.printStackTrace(); System.out.println("Thread " + threadName + " interrupted."); } System.out.println("Thread " + threadName + " exiting."); }
@Test public void runTestAndAssertCounters() throws Exception { final TrackingTestNGTestListener listener = new TrackingTestNGTestListener(); final TestNG testNG = new TestNG(); testNG.addListener(listener); testNG.setTestClasses(new Class<?>[] { this.clazz }); testNG.setVerbose(0); testNG.run(); assertEquals("Verifying number of test starts for test class [" + this.clazz + "].", this.expectedTestStartCount, listener.testStartCount); assertEquals("Verifying number of successful tests for test class [" + this.clazz + "].", this.expectedTestSuccessCount, listener.testSuccessCount); assertEquals("Verifying number of failures for test class [" + this.clazz + "].", this.expectedFailureCount, listener.testFailureCount); assertEquals("Verifying number of failed configurations for test class [" + this.clazz + "].", this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount); }
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); }
public static boolean checkTestNGInClasspath(PsiElement psiElement) { final Project project = psiElement.getProject(); final PsiManager manager = PsiManager.getInstance(project); if (JavaPsiFacade.getInstance(manager.getProject()).findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { if (Messages.showOkCancelDialog(psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) != Messages.OK) { return false; } } final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement); if (module == null) return false; String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class))); ModuleRootModificationUtil.addModuleLibrary(module, url); } return true; }
private void run() { LOG.debug("running tempto with options: {}", options); if (options.isHelpRequested()) { parser.printHelpMessage(); return; } XmlSuite testSuite = getXmlSuite(); testSuite.setThreadCount(options.getThreadCount()); setupTestsConfiguration(); System.setProperty(CONVENTION_TESTS_DIR_KEY, options.getConventionTestsDirectory()); TestNG testNG = new TestNG(); testNG.setXmlSuites(singletonList(testSuite)); testNG.setOutputDirectory(options.getReportDir()); setupTestsFiltering(testNG); options.getConventionResultsDumpPath() .ifPresent(path -> System.setProperty(CONVENTION_TESTS_RESULTS_DUMP_PATH_KEY, path)); testNG.run(); if (testNG.hasFailure()) { System.exit(1); } }
@Override public Callable<AnalysisResults> getExecutableTest(final Class<?> test) { final TestNG core = this.testCore; return new Callable<AnalysisResults>() { @Override public AnalysisResults call() { try { core.setTestClasses(new Class[]{test}); core.run(); AnalysisResults results = new AnalysisResults(); //results.put(JUNIT_TEST_RESULT, result); //results.put(TEST_CLASS_NAME, test.getName()); return results; // this.printTestRunSummary(); // TODO Move to AbstractRuntimeAnalyzer.runTests. } catch (Exception e) { e.printStackTrace(); } return null; } }; }
@Test public void runTestAndAssertCounters() throws Exception { final FailureTrackingTestListener listener = new FailureTrackingTestListener(); final TestNG testNG = new TestNG(); testNG.addListener(listener); testNG.setTestClasses(new Class<?>[] { this.clazz }); testNG.setVerbose(0); testNG.run(); assertEquals("Verifying number of test starts for test class [" + this.clazz + "].", this.expectedTestStartCount, listener.testStartCount); assertEquals("Verifying number of successful tests for test class [" + this.clazz + "].", this.expectedTestSuccessCount, listener.testSuccessCount); assertEquals("Verifying number of failures for test class [" + this.clazz + "].", this.expectedFailureCount, listener.testFailureCount); assertEquals("Verifying number of failed configurations for test class [" + this.clazz + "].", this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount); }
@Test public void testRunSampleTestNGClass() throws Exception { TestListenerAdapter tla = new TestListenerAdapter(); TestNG testng = new TestNG(); testng.setTestClasses(new Class[] {TestSubClass.class}); testng.addListener(tla); testng.run(); for (String item : this.outputFiles) { File file = new File(item); Assert.assertTrue( "The element '" + file.getAbsolutePath() + "' wasn't found", file.exists()); } for (String method : this.expectedMethods) { Assert.assertTrue( "Unable to find the call of method: " + method, AerialGluCode.getCallsList().contains(method)); } }
@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; }
public static boolean checkTestNGInClasspath(PsiElement psiElement) { final Project project = psiElement.getProject(); final PsiManager manager = PsiManager.getInstance(project); if (JavaPsiFacade.getInstance(manager.getProject()).findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { if (Messages.showOkCancelDialog(psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) != DialogWrapper.OK_EXIT_CODE) { return false; } } final Module module = ModuleUtil.findModuleForPsiElement(psiElement); if (module == null) return false; String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class))); ModuleRootModificationUtil.addModuleLibrary(module, url); } return true; }
@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(); }
@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")); }
private void runTests() { TestNG testNg = new TestNG(); testNg.setOutputDirectory(testReportDir.getAbsolutePath()); testNg.setDefaultSuiteName(options.getDefaultSuiteName()); testNg.setDefaultTestName(options.getDefaultTestName()); testNg.setParallel(options.getParallel()); testNg.setThreadCount(options.getThreadCount()); invokeVerifiedMethod(testNg, "setConfigFailurePolicy", String.class, options.getConfigFailurePolicy(), TestNGOptions.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())); //adding custom test listeners before Gradle's listeners. //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()) { testNg.addListener(new SelectedTestsFilter(options.getIncludedTests())); } if (!suiteFiles.isEmpty()) { testNg.setTestSuites(GFileUtils.toPaths(suiteFiles)); } else { testNg.setTestClasses(testClasses.toArray(new Class[0])); } testNg.addListener((Object) adaptListener(new TestNGTestResultProcessorAdapter(resultProcessor, idGenerator, timeProvider))); testNg.run(); }
private void invokeVerifiedMethod(TestNG testNg, String methodName, Class<?> paramClass, Object value, Object defaultValue) { try { JavaReflectionUtil.method(TestNG.class, Object.class, methodName, paramClass).invoke(testNg, value); } catch (NoSuchMethodException e) { if (!value.equals(defaultValue)) { // Should not reach this point as this is validated in the test framework implementation - just propagate the failure throw e; } } }
private InvokedMethodNameListener run(final String suitePath, final Supplier<BeforeMethodListener> listenerSupplier) { final TestNG tng = create(); final InvokedMethodNameListener nameListener = new InvokedMethodNameListener(); final BeforeMethodListener spyListener = listenerSupplier.get(); tng.addListener((ITestNGListener) nameListener); tng.addListener((ITestNGListener) spyListener); tng.setTestSuites(singletonList(suitePath)); tng.run(); return nameListener; }
/** * Constructs new {@link TestNGEngine} object with wanted listeners. * * @param listeners an instance (or instances) of engine's listeners * @return an instance of {@link TestNGEngine} */ @Override public TestNGEngine with(ITestNGListener... listeners) { final TestNG testNG = new TestNG(false); Arrays.stream(listeners).forEach(testNG::addListener); return new TestNGEngine(testNG, this.tests); }
@BeforeMethod(description = "Configure TestNG engine") public void prepare() { results = new AllureResultsWriterStub(); lifecycle = new AllureLifecycle(results); AllureTestNg adapter = new AllureTestNg(lifecycle); testNg = new TestNG(false); testNg.addListener((ITestNGListener) adapter); }
public void onStart( ISuite suite ) { // get the run name specified by the user String runName = CommonConfigurator.getInstance().getRunName(); if (runName.equals(CommonConfigurator.DEFAULT_RUN_NAME)) { // the user did not specify a run name, use the one from TestNG runName = suite.getName(); } // the following is needed in case when more than one RUN are executed sequentially // we need to clear some temporary data in the other listener we use TestNG testNgInstance = TestNG.getDefault(); // cleanup the class level listener new AtsTestngClassListener().resetTempData(); // cleanup the test level listener for (ITestListener listener : testNgInstance.getTestListeners()) { if (listener instanceof AtsTestngTestListener) { ((AtsTestngTestListener) listener).resetTempData(); } } // start a new run String hostNameIp = ""; try { InetAddress addr = InetAddress.getLocalHost(); hostNameIp = addr.getHostName() + "/" + addr.getHostAddress(); } catch (UnknownHostException uhe) { hostNameIp = null; } logger.startRun(runName, CommonConfigurator.getInstance().getOsName(), CommonConfigurator.getInstance().getProductName(), CommonConfigurator.getInstance().getVersionName(), CommonConfigurator.getInstance().getBuildName(), hostNameIp); logSystemInformation(); logClassPath(); }
@Test public void testSkipFromBefore() { ExecutionFlowController efc = new ExecutionFlowController(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{SkipFromBefore.class}); testNG.addListener((ITestNGListener) efc); testNG.addListener((ITestNGListener) tla); testNG.setConfigFailurePolicy(FailurePolicy.CONTINUE); testNG.run(); assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure"); assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure"); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration skip count"); assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count"); ITestResult methodResult = tla.getSkippedTests().get(0); assertEquals(methodResult.getName(), "testMethod", "Incorrect skipped test name"); assertEquals(SkipFromBefore.fromBefore, SkipFromBefore.VALUE, "Incorrect [before] value"); assertEquals(methodResult.getAttribute(SkipFromBefore.ATTRIBUTE), SkipFromBefore.VALUE, "Incorrect [method] value"); assertEquals(SkipFromBefore.fromAfter, SkipFromBefore.VALUE, "Incorrect [after] value"); }
@Test public void testMethodListenerExtension() { ExecutionFlowController efc = new ExecutionFlowController(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{MethodListenerExtension.class}); testNG.addListener((ITestNGListener) efc); testNG.addListener((ITestNGListener) tla); testNG.run(); assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure"); assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure"); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertTrue(MethodListenerExtension.beforeMethodBefore, "Incorrect [beforeMethod] 'before' value"); assertTrue(MethodListenerExtension.testMethodBefore, "Incorrect [testMethod] 'before' value"); assertTrue(MethodListenerExtension.afterMethodBefore, "Incorrect [afterMethod] 'before' value"); assertTrue(MethodListenerExtension.beforeMethodAfter, "Incorrect [beforeMethod] 'after' value"); assertTrue(MethodListenerExtension.testMethodAfter, "Incorrect [testMethod] 'after' value"); assertTrue(MethodListenerExtension.afterMethodAfter, "Incorrect [afterMethod] 'after' value"); }
@Test public void verifyTestFailed() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("testFailed"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSuccess.contains("beforeSuccess")); assertTrue(chainedListener.configSuccess.contains("afterSuccess")); assertTrue(chainedListener.beforeConfig.contains("beforeSuccess")); assertTrue(chainedListener.beforeConfig.contains("afterSuccess")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess")); assertTrue(chainedListener.testMethodBefore.contains("testFailed")); assertTrue(chainedListener.testMethodAfter.contains("testFailed")); assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess")); assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess")); assertTrue(chainedListener.testStarted.contains("testFailed")); assertTrue(chainedListener.testFailure.contains("testFailed")); }
@Test public void verifyTestSkipped() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("testSkipped"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSuccess.contains("beforeSuccess")); assertTrue(chainedListener.configSuccess.contains("afterSuccess")); assertTrue(chainedListener.beforeConfig.contains("beforeSuccess")); assertTrue(chainedListener.beforeConfig.contains("afterSuccess")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess")); assertTrue(chainedListener.testMethodBefore.contains("testSkipped")); assertTrue(chainedListener.testMethodAfter.contains("testSkipped")); assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess")); assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess")); assertTrue(chainedListener.testStarted.contains("testSkipped")); assertTrue(chainedListener.testSkipped.contains("testSkipped")); }
@Test public void verifyFailAndPass() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("failAndPass"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 3, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 1, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSuccess.contains("beforeSuccess")); assertTrue(chainedListener.configSuccess.contains("afterSuccess")); assertTrue(chainedListener.beforeConfig.contains("beforeSuccess")); assertTrue(chainedListener.beforeConfig.contains("afterSuccess")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess")); assertTrue(chainedListener.testMethodBefore.contains("failAndPass")); assertTrue(chainedListener.testMethodAfter.contains("failAndPass")); assertTrue(chainedListener.afterMethodBefore.contains("afterSuccess")); assertTrue(chainedListener.afterMethodAfter.contains("afterSuccess")); assertTrue(chainedListener.testStarted.contains("failAndPass")); assertTrue(chainedListener.testCurved.contains("failAndPass")); }
@Test public void verifyBeforeFailed() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("beforeFailed"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count"); assertTrue(chainedListener.configFailure.contains("beforeFailure")); assertTrue(chainedListener.configSkipped.contains("afterSuccess")); assertTrue(chainedListener.beforeConfig.contains("beforeFailure")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeFailure")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeFailure")); assertTrue(chainedListener.testMethodBefore.contains("skipBeforeFailed")); assertTrue(chainedListener.testMethodAfter.contains("skipBeforeFailed")); assertTrue(chainedListener.testStarted.contains("skipBeforeFailed")); assertTrue(chainedListener.testSkipped.contains("skipBeforeFailed")); }
@Test public void verifyBeforeSkipped() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("beforeSkipped"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 2, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSkipped.contains("beforeSkipped")); assertTrue(chainedListener.configSkipped.contains("afterSuccess")); assertTrue(chainedListener.beforeConfig.contains("beforeSkipped")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSkipped")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSkipped")); assertTrue(chainedListener.testMethodBefore.contains("skipBeforeSkipped")); assertTrue(chainedListener.testMethodAfter.contains("skipBeforeSkipped")); assertTrue(chainedListener.testStarted.contains("skipBeforeSkipped")); assertTrue(chainedListener.testSkipped.contains("skipBeforeSkipped")); }
@Test public void verifyAfterFailed() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("afterFailed"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 1, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSuccess.contains("beforeSuccess")); assertTrue(chainedListener.configFailure.contains("afterFailure")); assertTrue(chainedListener.beforeConfig.contains("beforeSuccess")); assertTrue(chainedListener.beforeConfig.contains("afterFailure")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess")); assertTrue(chainedListener.testMethodBefore.contains("testAfterFailed")); assertTrue(chainedListener.testMethodAfter.contains("testAfterFailed")); assertTrue(chainedListener.afterMethodBefore.contains("afterFailure")); assertTrue(chainedListener.afterMethodAfter.contains("afterFailure")); assertTrue(chainedListener.testStarted.contains("testAfterFailed")); assertTrue(chainedListener.testSuccess.contains("testAfterFailed")); }
@Test public void verifyAfterSkipped() { ListenerChain lc = new ListenerChain(); TestListenerAdapter tla = new TestListenerAdapter(); TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[]{ListenerChainTestCases.class}); testNG.addListener((ITestNGListener) lc); testNG.addListener((ITestNGListener) tla); testNG.setGroups("afterSkipped"); testNG.run(); ChainedListener chainedListener = lc.getAttachedListener(ChainedListener.class).get(); assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count"); assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count"); assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count"); assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count"); assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count"); assertEquals(tla.getConfigurationSkips().size(), 1, "Incorrect configuration method skip count"); assertTrue(chainedListener.configSuccess.contains("beforeSuccess")); assertTrue(chainedListener.configSkipped.contains("afterSkipped")); assertTrue(chainedListener.beforeConfig.contains("beforeSuccess")); assertTrue(chainedListener.beforeConfig.contains("afterSkipped")); assertTrue(chainedListener.beforeMethodBefore.contains("beforeSuccess")); assertTrue(chainedListener.beforeMethodAfter.contains("beforeSuccess")); assertTrue(chainedListener.testMethodBefore.contains("testAfterSkipped")); assertTrue(chainedListener.testMethodAfter.contains("testAfterSkipped")); assertTrue(chainedListener.afterMethodBefore.contains("afterSkipped")); assertTrue(chainedListener.afterMethodAfter.contains("afterSkipped")); assertTrue(chainedListener.testStarted.contains("testAfterSkipped")); assertTrue(chainedListener.testSuccess.contains("testAfterSkipped")); }
@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(); }
@SuppressWarnings("raw_types") public static void main(String[] args) { Class<?>[] testclass = { OnExitTest.class}; TestNG testng = new TestNG(); testng.setTestClasses(testclass); testng.run(); }
@SuppressWarnings("raw_types") public static void main(String[] args) { Class<?>[] testclass = {InfoTest.class}; TestNG testng = new TestNG(); testng.setTestClasses(testclass); testng.run(); }
@SuppressWarnings("raw_types") public static void main(String[] args) { Class<?>[] testclass = {TreeTest.class}; TestNG testng = new TestNG(); testng.setTestClasses(testclass); testng.run(); }