@Override public XmlTest getXmlTest() { return m_testContext.getCurrentXmlTest(); }
@Override public XmlTest getXmlTest() { return m_testContext.getCurrentXmlTest(); }
/** * @deprecated - This method stands deprecated as of TestNG v6.11. There are no alternatives. */ @Deprecated public static Object getInjectedParameter(Class<?> c, Method method, ITestContext context, ITestResult testResult) { Object result = null; if (Method.class.equals(c)) { result = method; } else if (ITestContext.class.equals(c)) { result = context; } else if (XmlTest.class.equals(c)) { result = context.getCurrentXmlTest(); } else if (ITestResult.class.equals(c)) { result = testResult; } return result; }
@Override public Object[] getInstances(boolean create) { Object[] result = {}; if (m_testContext.getCurrentXmlTest().isJUnit()) { if (create) { result = new Object[] { ClassHelper.createInstance(m_class, m_classes, m_testContext.getCurrentXmlTest(), m_annotationFinder, m_objectFactory) }; } } else { Object defaultInstance = getDefaultInstance(); if (defaultInstance != null) { result = new Object[]{defaultInstance}; } } if (m_instances.size() > 0) { result = m_instances.toArray(new Object[m_instances.size()]); } m_instanceCount = m_instances.size(); m_instanceHashCodes = new long[m_instanceCount]; for (int i = 0; i < m_instanceCount; i++) { m_instanceHashCodes[i] = m_instances.get(i).hashCode(); } return result; }
private static boolean excludeFactory(FactoryMethod fm, ITestContext ctx) { return fm.getGroups().length != 0 && ctx.getCurrentXmlTest().getExcludedGroups().containsAll(Arrays.asList(fm.getGroups())); }
private Object getDefaultInstance() { if (m_defaultInstance == null) { if (m_instance != null) { m_defaultInstance = m_instance; } else { Object instance = getInstanceFromGuice(); if (instance != null) { m_defaultInstance = instance; } else { m_defaultInstance = ClassHelper.createInstance(m_class, m_classes, m_testContext.getCurrentXmlTest(), m_annotationFinder, m_objectFactory); } } } return m_defaultInstance; }
private static boolean excludeFactory(FactoryMethod fm, ITestContext ctx) { return fm.getGroups().length != 0 && ctx.getCurrentXmlTest().getExcludedGroups().containsAll(Arrays.asList(fm.getGroups())); }
attrs.setProperty(XMLConstants.ATTR_NAME, context.getCurrentXmlTest().getName());
public static MethodParameters newInstance(Map<String, String> params, ITestNGMethod testNGMethod, ITestContext context) { Map<String, String> methodParams = testNGMethod.findMethodParameters(context.getCurrentXmlTest()); Object[] pv = null; ITestResult tr = null; Method method = testNGMethod.getConstructorOrMethod().getMethod(); return new MethodParameters(params, methodParams, pv, method, context, tr); }
@Test public void testMethod() { if ("testcontext".equalsIgnoreCase(whatWasPassed)) { // only testcontext was provided assertNotNull(ctx); currentXmlTest = ctx.getCurrentXmlTest(); } assertNotNull(currentXmlTest); int number = Integer.parseInt(currentXmlTest.getParameter("number")); assertTrue(number != 0); } }
@Override public void onStart(ITestContext context) { messages.add("Executing " + context.getCurrentXmlTest().getName()); }
@Test public void test(ITestContext context) { Assert.assertEquals(context.getCurrentXmlTest().getPreserveOrder(), XmlSuite.DEFAULT_PRESERVE_ORDER); } }
protected static void invokeWithTimeout(ITestNGMethod tm, Object instance, Object[] parameterValues, ITestResult testResult, IHookable hookable) throws InterruptedException, ThreadExecutionException { if (ThreadUtil.isTestNGThread() && testResult.getTestContext().getCurrentXmlTest().getParallel() != XmlSuite.ParallelMode.TESTS) { // We are already running in our own executor, don't create another one (or we will // lose the time out of the enclosing executor). invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable); } else { invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult, hookable); } }
@Override public void onConfigurationSuccess(ITestResult itr) { String xmlTestName = itr.getTestContext().getCurrentXmlTest().getName(); Integer count = CALLS.get(xmlTestName); if (count == null) { count = 0; } count++; CALLS.put(xmlTestName, count); }
public static MethodParameters newInstance( Map<String, String> params, ITestNGMethod testNGMethod, ITestContext context) { Map<String, String> methodParams = testNGMethod.findMethodParameters(context.getCurrentXmlTest()); Method method = testNGMethod.getConstructorOrMethod().getMethod(); return new MethodParameters(params, methodParams, null, method, context, null); }
@Override public Module createModule(ITestContext context, Class<?> testClass) { String parameter = context.getCurrentXmlTest().getParameter("inject"); String expected = "guice"; if (!expected.equals(parameter)) { throw new RuntimeException("Excepted parameter to be " + expected + ", got " + parameter); } if (GuiceModuleFactoryTest.class == testClass) { return new GuiceExampleModule(); } else { throw new RuntimeException("Don't know how to create a module for class " + testClass); } } }
private ParameterBag handleParameters(ITestNGMethod testMethod, Object instance, Map<String, String> allParameterNames, Map<String, String> parameters, ITestContext testContext, Object fedInstance) { XmlSuite suite = testContext.getCurrentXmlTest().getSuite(); try { MethodParameters methodParams = MethodParameters.newInstance(parameters, testMethod, testContext); ParameterHolder paramHolder = Parameters.handleParameters(testMethod, allParameterNames, instance, methodParams, suite, finder, fedInstance, listeners); return new ParameterBag(paramHolder); } catch (Throwable cause) { String msg = Utils.longStackTrace(cause.getCause() != null ? cause.getCause() : cause, true); if (Strings.isNotNullAndNotEmpty(msg)) { Utils.error(msg); } ITestResult result = new TestResult(instance, testMethod, cause, testContext); return new ParameterBag(result); } }
@Override public List<IWorker<ITestNGMethod>> createWorkers(Arguments arguments) { ListMultiMap<Object, ITestNGMethod> lmm = Maps.newSortedListMultiMap(); for (ITestNGMethod m : arguments.getMethods()) { lmm.put(m.getInstance(), m); } List<IWorker<ITestNGMethod>> result = Lists.newArrayList(); for (Map.Entry<Object, List<ITestNGMethod>> es : lmm.entrySet()) { List<IMethodInstance> methodInstances = MethodHelper.methodsToMethodInstances(es.getValue()); TestMethodWorker tmw = new TestMethodWorker(arguments.getInvoker(), methodInstances, arguments.getTestContext().getCurrentXmlTest().getSuite(), arguments.getTestContext().getCurrentXmlTest().getAllParameters(), arguments.getConfigMethods(), arguments.getClassMethodMap(), arguments.getTestContext(), arguments.getListeners()); result.add(tmw); } return result; } }
private static TestMethodWorker createTestMethodWorker(Arguments attributes, List<IMethodInstance> methodInstances, Map<String, String> params, Class<?> c) { return new TestMethodWorker(attributes.getInvoker(), findClasses(methodInstances, c), attributes.getTestContext().getCurrentXmlTest().getSuite(), params, attributes.getConfigMethods(), attributes.getClassMethodMap(), attributes.getTestContext(), attributes.getListeners()); }
protected void generateFailureSuite(XmlSuite xmlSuite, ISuite suite, String outputDir) { XmlSuite failedSuite = xmlSuite.shallowCopy(); failedSuite.setName("Failed suite [" + xmlSuite.getName() + "]"); m_xmlSuite= failedSuite; Map<String, ISuiteResult> results = suite.getResults(); for(Map.Entry<String, ISuiteResult> entry : results.entrySet()) { ISuiteResult suiteResult = entry.getValue(); ITestContext testContext = suiteResult.getTestContext(); generateXmlTest(testContext.getCurrentXmlTest(), testContext, testContext.getFailedTests().getAllResults(), testContext.getSkippedTests().getAllResults()); } if(null != failedSuite.getTests() && failedSuite.getTests().size() > 0) { Utils.writeUtf8File(outputDir, TESTNG_FAILED_XML, failedSuite.toXml()); Utils.writeUtf8File(suite.getOutputDirectory(), TESTNG_FAILED_XML, failedSuite.toXml()); } }