Esempio n. 1
0
  /**
   * Invoke the @AfterClass methods if not done already
   *
   * @param testClass
   * @param mi
   */
  protected void invokeAfterClassMethods(ITestClass testClass, IMethodInstance mi) {
    // if no BeforeClass than return immediately
    // used for parallel case when BeforeClass were already invoked
    if ((null == m_classMethodMap) || (null == m_classMethodMap.getInvokedAfterClassMethods())) {
      return;
    }
    ITestNGMethod[] afterClassMethods = testClass.getAfterClassMethods();

    if (null == afterClassMethods || afterClassMethods.length == 0) {
      return;
    }

    //
    // Invoke after class methods if this test method is the last one
    //
    List<Object> invokeInstances = Lists.newArrayList();
    ITestNGMethod tm = mi.getMethod();
    if (m_classMethodMap.removeAndCheckIfLast(tm, mi.getInstances()[0])) {
      Map<ITestClass, Set<Object>> invokedAfterClassMethods =
          m_classMethodMap.getInvokedAfterClassMethods();
      synchronized (invokedAfterClassMethods) {
        Set<Object> instances = invokedAfterClassMethods.get(testClass);
        if (null == instances) {
          instances = new HashSet<Object>();
          invokedAfterClassMethods.put(testClass, instances);
        }
        for (Object inst : mi.getInstances()) {
          if (!instances.contains(inst)) {
            invokeInstances.add(inst);
          }
        }
      }

      for (Object inst : invokeInstances) {
        m_invoker.invokeConfigurations(
            testClass,
            afterClassMethods,
            m_suite,
            m_parameters,
            null, /* no parameter values */
            inst);
      }
    }
  }
Esempio n. 2
0
  protected void invokeTestMethods(ITestNGMethod tm, Object[] instances, ITestContext testContext) {
    // Potential bug here:  we look up the method index of tm among all
    // the test methods (not very efficient) but if this method appears
    // several times and these methods are run in parallel, the results
    // are unpredictable...  Need to think about this more (and make it
    // more efficient)
    List<ITestResult> testResults =
        m_invoker.invokeTestMethods(
            tm,
            m_allTestMethods,
            indexOf(tm, m_allTestMethods),
            m_suite,
            m_parameters,
            m_groupMethods,
            instances,
            testContext);

    if (testResults != null) {
      m_testResults.addAll(testResults);
    }
  }
Esempio n. 3
0
  /**
   * Invoke the @BeforeClass methods if not done already
   *
   * @param testClass
   * @param mi
   */
  protected void invokeBeforeClassMethods(ITestClass testClass, IMethodInstance mi) {
    // if no BeforeClass than return immediately
    // used for parallel case when BeforeClass were already invoked
    if ((null == m_classMethodMap) || (null == m_classMethodMap.getInvokedBeforeClassMethods())) {
      return;
    }
    ITestNGMethod[] classMethods = testClass.getBeforeClassMethods();
    if (null == classMethods || classMethods.length == 0) {
      return;
    }

    // the whole invocation must be synchronized as other threads must
    // get a full initialized test object (not the same for @After)
    Map<ITestClass, Set<Object>> invokedBeforeClassMethods =
        m_classMethodMap.getInvokedBeforeClassMethods();
    //    System.out.println("SYNCHRONIZING ON " + testClass
    //        + " thread:" + Thread.currentThread().getId()
    //        + " invokedMap:" + invokedBeforeClassMethods.hashCode() + " "
    //        + invokedBeforeClassMethods);
    synchronized (testClass) {
      Set<Object> instances = invokedBeforeClassMethods.get(testClass);
      if (null == instances) {
        instances = new HashSet<Object>();
        invokedBeforeClassMethods.put(testClass, instances);
      }
      for (Object instance : mi.getInstances()) {
        if (!instances.contains(instance)) {
          instances.add(instance);
          m_invoker.invokeConfigurations(
              testClass,
              testClass.getBeforeClassMethods(),
              m_suite,
              m_parameters,
              null, /* no parameter values */
              instance);
        }
      }
    }
  }