Package org.testng

Examples of org.testng.TestNGException


        m_signature= m_methodClass.getName() + "." + m_methodName + "()";
        try {
          m_method= test.getClass().getMethod(tc.getName(), new Class[0]);
        }
        catch(Exception ex) {
          throw new TestNGException("cannot retrieve JUnit method", ex);
        }
      }
    }
View Full Code Here


    if(parameterTypes.length > 0) {
      List<Object> vResult = new ArrayList<Object>();
 
      if (parameterNames.length != parameterTypes.length
          && parameterTypes.length != parameterNames.length + 1) {
        throw new TestNGException( "Method " + methodName + " needs "
            + parameterTypes.length + " parameters but "
            + parameterNames.length
            + " were supplied in the "
            + methodAnnotation
            + " annotation.");
      }
 
      int i= 0;
      int j= 0;
      for(; i < parameterTypes.length; i++) {
          if(Method.class.equals(parameterTypes[i])) {
              vResult.add(params.m_currentTestMethod);
          }
          else {
              String p = parameterNames[j];
              String value = params.m_parameters.get(p);
              if (null == value) {
                throw new TestNGException("Parameter '" + p + "' is required by "
                    + methodAnnotation
                    + " on method "
                    + methodName
                    + "\nbut has not been defined in " + xmlSuite.getFileName());
              }
View Full Code Here

    for (Method m : ClassHelper.getAvailableMethods(cls)) {
      IDataProvider dp = (IDataProvider) finder.findAnnotation(m, IDataProvider.class);
      if (null != dp && (name.equals(dp.getName()) || name.equals(m.getName()))) {
        if (shouldBeStatic && (m.getModifiers() & Modifier.STATIC) == 0) {
          throw new TestNGException("DataProvider should be static: " + m);
        }
       
        return m;
      }
    }
View Full Code Here

          }
        }
      }
     
      if (!foundAtLeastAMethod) {
        throw new TestNGException(mainMethod
            + "() is depending on nonexistent method " + currentRegexp);
      }
    }

    ITestNGMethod[] result = vResult.toArray(new ITestNGMethod[vResult.size()]);
View Full Code Here

      // Go through all the parameters declared on this Data Provider and
      // make sure we have at most one Method and one ITestContext.
      // Anything else is an error
      Class[] parameterTypes = dataProvider.getParameterTypes();
      if (parameterTypes.length > 2) {
        throw new TestNGException("DataProvider " + dataProvider + " cannot have more than two parameters");
      }
     
      for (Class cls : parameterTypes) {
        if (cls.equals(Method.class)) {
          lParameters.add(testMethod);
        }
        else if (cls.equals(ITestContext.class)) {
          lParameters.add(testContext);
        }
      }
      Object[] parameters = lParameters.toArray(new Object[lParameters.size()]);
//      if (parameterTypes.length > 0 && parameterTypes[0].equals(Method.class)) {
//        parameters = new Object[] {
//          testMethod
//        };
//      }
//      else if (parameterTypes.length > 0) {
//        throw new TestNGException("DataProvider " + dataProvider + " needs to have "
//            + " either zero parameters or one parameter of type java.lang.reflect.Method");
//      }
     
      Class< ? > returnType = dataProvider.getReturnType();
      if (Object[][].class.isAssignableFrom(returnType)) {
        Object[][] oResult = (Object[][]) MethodHelper.invokeMethod(
            dataProvider, instance, parameters);
        method.setParameterInvocationCount(oResult.length);
        result = MethodHelper.createArrayIterator(oResult);
      }
      else if (Iterator.class.isAssignableFrom(returnType)) {
        // Already an Iterable<Object[]>, assign it directly
        result = (Iterator<Object[]>) MethodHelper.invokeMethod(dataProvider,
            instance, parameters);
      }
      else {
        throw new TestNGException("Data Provider " + dataProvider
            + " must return" + " either Object[][] or Iterator<Object>[], not "
            + returnType);
      }
    }
    catch (InvocationTargetException e) {
      throw new TestNGException(e);
    }
    catch (IllegalAccessException e) {
      throw new TestNGException(e);
    }

    return result;
  }
View Full Code Here

      interpreter.set("method", method);
      interpreter.set("groups", groups);
      interpreter.set("testngMethod", tm);
    }
    catch(EvalError evalError) {
      throw new TestNGException("Cannot set BSH interpreter", evalError);
    }
  }
View Full Code Here

        cause= fcerr;
      }
    }
   
    if(null == spf) {     
      throw new TestNGException("Cannot initialize a SAXParserFactory\n" + errorLog.toString(), cause);
    }
   
    return spf;
  }
View Full Code Here

  public Class getSupportClass() {
    if(null == m_class) {
      m_class = ClassHelper.forName(m_name);
     
      if(null == m_class) {
        throw new TestNGException("Cannot find class in classpath: " + m_name);
      }
    }

    return m_class;
  }
View Full Code Here

      Object instance = clazz.newInstance();

      return instance;
    }
    catch(IllegalAccessException iae) {
      throw new TestNGException("Class " + clazz.getName() + " does not have a no-args constructor", iae);
    }
    catch(InstantiationException ie) {
      throw new TestNGException("Cannot instantiate class " + clazz.getName(), ie);
    }
    catch(ExceptionInInitializerError eiierr) {
      throw new TestNGException("An exception occurred in static initialization of class " + clazz.getName(),
          eiierr);
    }
    catch(SecurityException se) {
      throw new TestNGException(se);
    }
  }
View Full Code Here

    for (Method method : cls.getDeclaredMethods()) {
      IAnnotation f = finder.findAnnotation(method, IFactory.class);

      if (null != f) {
        if (null != result) {
          throw new TestNGException(cls.getName() + ":  only one @Factory method allowed");
        }
        result = method;
      }
    }
View Full Code Here

TOP

Related Classes of org.testng.TestNGException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.