@Override public void onStart(ISuite suite) { suite.setParentInjector(injector); long numberOfEnabledTests = suite.getAllMethods().parallelStream().filter(ITestNGMethod::getEnabled).count(); LOG.info("Starting suite '{}' with {} test methods.", suite.getName(), numberOfEnabledTests); }
/** * Disables the {@code @BeforeMethod} and {@code @AfterMethod} configuration methods of all test * classes, overriding the corresponding private fields of {@code TestClass}. * <p> * These methods shall run only once inside the test container, but not directly under the * driver. * <p> * This is a rather ugly hack, but there does not seem to be any other way. * * @param suite * test suite */ private void disableConfigurationMethods(ISuite suite) { Set<ITestClass> seen = new HashSet<ITestClass>(); for (ITestNGMethod method : suite.getAllMethods()) { ITestClass testClass = method.getTestClass(); if (!seen.contains(testClass)) { disableConfigurationMethods(testClass); seen.add(testClass); } } }
@Override public void onStart(ISuite suite) { List<String> errors = new ArrayList<>(); Set<Class> classes = new HashSet<>(); checkAnnotations(errors, classes, suite.getExcludedMethods()); checkAnnotations(errors, classes, suite.getAllMethods()); if (!errors.isEmpty()) { throw new TestNGException(String.join("\n", errors)); } saveInitialThreads(); suiteRunning = true; }
/** * Stages the reactor. This involves building the probe including all test methods of the suite * and creating one or more test containers. * <p> * When using a probe invoker, we register the tests with the reactor. * * @param suite * test suite * @return staged reactor */ private synchronized StagedExamReactor stageReactor(ISuite suite) { try { methods = suite.getAllMethods(); Class<?> testClass = methods.get(0).getRealClass(); LOG.debug("test class = {}", testClass); Object testClassInstance = testClass.newInstance(); return stageReactorForClass(testClass, testClassInstance); } catch (InstantiationException | IllegalAccessException exc) { throw new TestContainerException(exc); } }
@Override public void onStart(ITestContext context) { Logger logger = getLogger(); logger.debug("Starting tests"); if (logger.isDebugEnabled()) { logger.trace("host: " + context.getHost()); logger.trace("suite name: " + context.getSuite().getName()); logger.trace("parallel: " + context.getSuite().getParallel()); logger.trace("included groups: " + StringUtils.join(context.getIncludedGroups(), ", ")); logger.trace("excluded groups: " + StringUtils.join(context.getExcludedGroups(), ", ")); } if (logger.isTraceEnabled()) { ISuite suite = context.getSuite(); XmlSuite xmlSuite = suite.getXmlSuite(); logger.trace("thread count: " + xmlSuite.getThreadCount()); logger.trace("data provider thread count: " + xmlSuite.getDataProviderThreadCount()); logger.trace("methods: " + StringUtils.join(suite.getAllMethods(), ", ")); logger.trace("excluded methods: " + StringUtils.join(suite.getExcludedMethods(), ", ")); Set<Entry<String, String>> allParameters = xmlSuite.getAllParameters().entrySet(); for (Entry<String, String> entry : allParameters) { logger.trace(entry.getKey() + "='" + entry.getValue() + "'"); } } }
/** * Stages the reactor. This involves building the probe including all test methods of the suite * and creating one or more test containers. * <p> * When using a probe invoker, we register the tests with the reactor. * <p> * Hack: As there is no way to intercept configuration methods, we disable them by reflection. * * @param suite * test suite * @return staged reactor */ private synchronized StagedExamReactor stageReactor(ISuite suite) { try { methods = suite.getAllMethods(); Class<?> testClass = methods.get(0).getRealClass(); LOG.debug("test class = {}", testClass); disableConfigurationMethods(suite); Object testClassInstance = testClass.newInstance(); return stageReactorForClass(testClass, testClassInstance); } catch (InstantiationException | IllegalAccessException exc) { throw new TestContainerException(exc); } }
@Override public void onStart(ITestContext context) { Logger logger = getLogger(); logger.debug("Starting tests"); if (logger.isDebugEnabled()) { logger.trace("host: " + context.getHost()); logger.trace("suite name: " + context.getSuite().getName()); logger.trace("parallel: " + context.getSuite().getParallel()); logger.trace("included groups: " + StringUtils.join(context.getIncludedGroups(), ", ")); logger.trace("excluded groups: " + StringUtils.join(context.getExcludedGroups(), ", ")); } if (logger.isTraceEnabled()) { ISuite suite = context.getSuite(); XmlSuite xmlSuite = suite.getXmlSuite(); logger.trace("thread count: " + xmlSuite.getThreadCount()); logger.trace("data provider thread count: " + xmlSuite.getDataProviderThreadCount()); logger.trace("methods: " + StringUtils.join(suite.getAllMethods(), ", ")); logger.trace("excluded methods: " + StringUtils.join(suite.getExcludedMethods(), ", ")); Set<Entry<String, String>> allParameters = xmlSuite.getAllParameters().entrySet(); for (Entry<String, String> entry : allParameters) { logger.trace(entry.getKey() + "='" + entry.getValue() + "'"); } } }
@Override public void onStart(ISuite suite) { rules = parseRules(Configuration.get(Configuration.Parameter.TEST_RUN_RULES)); // rules are absent if (rules.isEmpty()) { LOGGER.info("There are no any rules and limitations"); return; } boolean isPerform; LOGGER.info("Extracted rules: ".concat(rules.toString())); for (ITestNGMethod testMethod : suite.getAllMethods()) { isPerform = true; // multiple conditions for (Rule rule : rules) { // condition when test doesn't satisfy at least one filter if (!isPerform) { break; } isPerform = rule.getTestFilter().isPerform(testMethod, rule.getRuleValues()); } // condition when test should be disabled if (!isPerform) { disableTest(testMethod); } } }
@Override public void onStart(ISuite suite) { List<String> testMethodNames = getTestMethodNames(suite.getAllMethods()); List<String> excludedTestMethodNames = getTestMethodNames(suite.getExcludedMethods()); System.out.println("\n(" + getDateTime() + ")" + " Running suite [" + suite.getName() + "] containing tests " + testMethodNames + " --- excluding tests " + excludedTestMethodNames + "..."); }
@Override public void onStart(ISuite suite) { List<String> testMethodNames = getTestMethodNames(suite.getAllMethods()); List<String> excludedTestMethodNames = getTestMethodNames(suite.getExcludedMethods()); System.out.println("\n(" + getDateTime() + ")" + " Running suite [" + suite.getName() + "] containing tests " + testMethodNames + " --- excluding tests " + excludedTestMethodNames + "..."); }
private boolean hasDependencies(ITestResult result) { String methodName = result.getMethod().getMethodName(); String className = result.getMethod().getTestClass().getName(); LOGGER.debug("current method: " + className + "." + methodName); // analyze all suite methods and return true if any of them depends on // existing method List<ITestNGMethod> methods = result.getTestContext().getSuite().getAllMethods(); for (ITestNGMethod method : methods) { LOGGER.debug("analyze method for dependency: " + method.getMethodName()); List<String> dependencies = Arrays.asList(method.getMethodsDependedUpon()); if (dependencies.contains(methodName) || dependencies.contains(className + "." + methodName)) { return true; } } return false; }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { if (!method.isTestMethod()) { return; } // Note that TCK is processing test classes sequentially in one thread - see also SingleTestClassMethodInterceptor if (totalCountOfMethods == null) { totalCountOfMethods = context.getSuite().getAllMethods().size(); } String testClassName = method.getTestMethod().getTestClass().getName(); if (!testClassName.equals(lastTestClassName)) { processedTestClasses.incrementAndGet(); lastTestClassName = testClassName; } logger.log(Level.INFO, "Invoke {0}.{1}: {2}/{3} Failed tests: {4} ({5})", new Object[] { method.getTestMethod().getTestClass().getRealClass().getSimpleName(), method.getTestMethod().getMethodName(), testMethodInvocations.incrementAndGet(), totalCountOfMethods, context.getFailedTests().size(), processedTestClasses.get() }); }
if (suite != null && suite.getAllInvokedMethods().size() < suite.getAllMethods().size()) { for (ITestNGMethod ngMethod : suite.getAllMethods()) { if (ngMethod.isTest()) { boolean methodInvoked = false;
for (ITestNGMethod testNGMethod : suite.getAllMethods()) for (ITestNGMethod testNGMethod : suite.getAllMethods())
for (ITestNGMethod testNGMethod : suite.getAllMethods()) for (ITestNGMethod testNGMethod : suite.getAllMethods())
/** * Counts a number of the methods and printed it to the output stream with the test suite name. * * @param suite test suite */ public void onSuiteStart(ISuite suite) { if (suite != null) { try { List<ITestNGMethod> allMethods = suite.getAllMethods(); if (allMethods != null) { int count = 0; for (ITestNGMethod method : allMethods) { if (method.isTest()) { count += method.getInvocationCount(); } } methodCount(out, count); } } catch (NoSuchMethodError ignore) { } rootPresentation(out, suite.getName(), suite.getXmlSuite().getFileName()); } }