public ConfigInvoker(ITestResultNotifier notifier, Collection<IInvokedMethodListener> invokedMethodListeners, ITestContext testContext, SuiteRunState suiteState, IConfiguration configuration) { super(notifier, invokedMethodListeners, testContext, suiteState, configuration); this.m_continueOnFailedConfiguration = testContext.getSuite().getXmlSuite().getConfigFailurePolicy() == XmlSuite.FailurePolicy.CONTINUE; }
/** * This method guarantees unique file names for reports.<br> * Also, this will guarantee that the old reports are overwritten when tests are run again. * * @param context * test context * @return unique name for the file associated with this test context. * */ private String generateFileName(ITestContext context) { String fileName; String keyToSearch = context.getSuite().getName() + context.getName(); if (m_fileNameMap.get(keyToSearch) == null) { fileName = context.getName(); } else { fileName = context.getName() + m_fileNameIncrementer++; } m_fileNameMap.put(keyToSearch, fileName); return fileName; } }
@Test(groups = "broken") public void iSuiteShouldBeSerializable(ITestContext context) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(context.getSuite()); oos.close(); }
public Invoker(IConfiguration configuration, ITestContext testContext, ITestResultNotifier notifier, SuiteRunState state, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Collection<IDataProviderListener> dataProviderListeners) { m_configuration = configuration; m_testContext= testContext; m_suiteState= state; m_notifier= notifier; m_annotationFinder= configuration.getAnnotationFinder(); m_skipFailedInvocationCounts = skipFailedInvocationCounts; m_invokedMethodListeners = invokedMethodListeners; m_continueOnFailedConfiguration = testContext.getSuite().getXmlSuite().getConfigFailurePolicy() == XmlSuite.FailurePolicy.CONTINUE; m_classListeners = classListeners; m_dataproviderListeners = dataProviderListeners; }
/** * This method guarantees unique file names for reports.<br> * Also, this will guarantee that the old reports are overwritten when tests are run again. * * @param context test context * @return unique name for the file associated with this test context. */ private String generateFileName(ITestContext context) { String fileName; String keyToSearch = context.getSuite().getName() + context.getName(); if (m_fileNameMap.get(keyToSearch) == null) { fileName = context.getName(); } else { fileName = context.getName() + m_fileNameIncrementer++; } m_fileNameMap.put(keyToSearch, fileName); return fileName; } }
@Override public void onStart(ITestContext ctx) { suiteName = ctx.getName(); log("RUNNING: Suite: \"" + suiteName + "\" containing \"" + ctx.getAllTestMethods().length + "\" Tests (config: " + ctx.getSuite().getXmlSuite().getFileName() + ")"); }
@Test public void xmlFileShouldBeRunAtItsPlaceAndNotCopied(ITestContext ctx) { String fileName = ctx.getSuite().getXmlSuite().getFileName().replace("\\", "/"); Assert.assertTrue(fileName.contains("src/test/resources")); } }
@BeforeClass(enabled = false) public void setupClass(ITestContext testContext) { assertEquals( testContext.getSuite().getXmlSuite().getConfigFailurePolicy(), XmlSuite.FailurePolicy.CONTINUE); }
public void testService() { Assert.assertNotNull(myService); Assert.assertNotNull(mySession); myService.serve(mySession); Assert.assertNotNull(context); Assert.assertEquals(context.getName(), "Guice"); Assert.assertEquals(context.getSuite().getName(), "parent-module-suite"); } }
public ClassImpl(ITestContext context, Class<?> cls, XmlClass xmlClass, Object instance, Map<Class<?>, IClass> classes, IAnnotationFinder annotationFinder, ITestObjectFactory objectFactory) { m_testContext = context; m_class = cls; m_classes = classes; m_xmlClass = xmlClass; m_annotationFinder = annotationFinder; m_instance = instance; m_objectFactory = objectFactory; if (instance instanceof ITest) { m_testName = ((ITest) instance).getTestName(); } if (m_testName == null) { ITestAnnotation annotation = m_annotationFinder.findAnnotation(cls, ITestAnnotation.class); if (annotation != null && !annotation.getTestName().isEmpty()) { m_testName = annotation.getTestName(); } } m_hasParentModule = isStringNotEmpty(m_testContext.getSuite().getParentModule()); }
@BeforeMethod public void before(ITestContext ctx) { logSuite(ctx.getSuite().getName(), System.currentTimeMillis()); }
/** * Writes the specified ISuiteResult in the given XMLStringBuffer. Please consider that depending on the settings in * the <code>config</code> property it might generate an additional XML file with the actual content and only * reference the file with an <code>url</code> attribute in the passed XMLStringBuffer. * * @param xmlBuffer The XML buffer where to write or reference the suite result * @param suiteResult The <code>ISuiteResult</code> to serialize */ public void writeSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) { if (XMLReporterConfig.FF_LEVEL_SUITE_RESULT != config.getFileFragmentationLevel()) { writeAllToBuffer(xmlBuffer, suiteResult); } else { String parentDir = config.getOutputDirectory() + File.separatorChar + suiteResult.getTestContext().getSuite().getName(); File file = referenceSuiteResult(xmlBuffer, parentDir, suiteResult); XMLStringBuffer suiteXmlBuffer = new XMLStringBuffer(); writeAllToBuffer(suiteXmlBuffer, suiteResult); Utils.writeUtf8File(file.getAbsoluteFile().getParent(), file.getName(), suiteXmlBuffer.toXML()); } }
@AfterClass public void afterClass(ITestContext context) { ITestResult result = context.getSuite().getAllInvokedMethods().get(0).getTestResult(); endTimestamp = result.getEndMillis(); endStatus = ITestResult.SUCCESS; } }
@Override public void onStart(ITestContext ctx) { suiteName = ctx.getName(); log( "RUNNING: Suite: \"" + suiteName + "\" containing \"" + ctx.getAllTestMethods().length + "\" Tests (config: " + ctx.getSuite().getXmlSuite().getFileName() + ")"); }
private static Throwable getConfigFailureException(ITestContext context) { for (IInvokedMethod method : context.getSuite().getAllInvokedMethods()) { ITestNGMethod m = method.getTestMethod(); if (m.isBeforeSuiteConfiguration() && (!method.getTestResult().isSuccess())) { return method.getTestResult().getThrowable(); } } return null; }
@BeforeClass public void beforeClass(ITestContext context) throws InterruptedException { TimeUnit.SECONDS.sleep(1); ITestResult result = context.getSuite().getAllInvokedMethods().get(0).getTestResult(); startStatus = result.getStatus(); startTimestamp = result.getEndMillis(); }
public Injector getParentInjector() { ISuite suite = m_testContext.getSuite(); // Reuse the previous parent injector, if any Injector injector = suite.getParentInjector(); if (injector == null) { String stageString = suite.getGuiceStage(); Stage stage; if (isStringNotEmpty(stageString)) { stage = Stage.valueOf(stageString); } else { stage = Stage.DEVELOPMENT; } if (m_hasParentModule) { Class<Module> parentModule = (Class<Module>) ClassHelper.forName(suite.getParentModule()); if (parentModule == null) { throw new TestNGException("Cannot load parent Guice module class: " + suite.getParentModule()); } Module module = newModule(parentModule); injector = com.google.inject.Guice.createInjector(stage, module); } else { injector = com.google.inject.Guice.createInjector(stage); } suite.setParentInjector(injector); } return injector; }
/** * 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 static Throwable getConfigFailureException(ITestContext context) { for (IInvokedMethod method : context.getSuite().getAllInvokedMethods()) { ITestNGMethod m = method.getTestMethod(); if (m.isBeforeSuiteConfiguration() && (!method.getTestResult().isSuccess())) { return method.getTestResult().getThrowable(); } } return null; } }
private TestNgRunStateTracker.EventLogBuilder buildEventLog(ITestContext context, TestNgRunEvent event) { return buildEventLog(context.getSuite(), event) .addData(TEST_NAME, context.getName()); }