org.testng.TestNGException Java Examples

The following examples show how to use org.testng.TestNGException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Helpers.java    From AppiumTestDistribution with GNU General Public License v3.0 6 votes vote down vote up
protected List<ITestNGListener> initialiseListeners() {
    List<ITestNGListener> listeners = new LinkedList<>();
    String file = "META-INF/services/listeners.txt";
    InputStream stream = getStream(file);
    if (stream != null) {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
            String line;
            while ((line = reader.readLine()) != null) {
                listeners.add(instantiate(line));
            }
        } catch (IOException e) {
            throw new TestNGException(e);
        }
    }
    return listeners;
}
 
Example #2
Source File: Helpers.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
private static ITestNGListener instantiate(String className) {
    if (className == null || className.trim().isEmpty()) {
        throw new IllegalArgumentException("Please provide a valid class name");
    }
    try {
        Class<?> clazz = Class.forName(className);
        if (!ITestNGListener.class.isAssignableFrom(clazz)) {
            throw new IllegalArgumentException(className
                + " does not implement a TestNG listener");
        }
        return (ITestNGListener) clazz.newInstance();
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new TestNGException(e);
    }
}
 
Example #3
Source File: Test_BasicDataProvider.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFile = "Test_BasicDataProvider", dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_noFileExtension( String user, String pswd, String subject ) {}
 
Example #4
Source File: Test_BasicDataProvider.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFileFolder = TestDetails.DATA_FILES_FOLDER, dataFile = TestDetails.DATA_FILE1
                                                                         + "NON_EXISTING_FILE", dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_wrongFile( String user, String pswd, String subject ) {}
 
Example #5
Source File: Test_BasicDataProviderWithoutClassAnnotation.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFile = TestDetails.DATA_FILE2, dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFileFolder_fromClassAnnotation( String user, String pswd, String subject ) {}
 
Example #6
Source File: Test_BasicDataProviderWithoutClassAnnotation.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_fromClasspath_negative( String user, String pswd, String subject ) {}
 
Example #7
Source File: MethodHelper.java    From qaf with MIT License 4 votes vote down vote up
/**
 * Finds TestNG methods that the specified TestNG method depends upon
 * @param m TestNG method
 * @param methods list of methods to search for depended upon methods
 * @return list of methods that match the criteria
 */
protected static ITestNGMethod[] findDependedUponMethods(ITestNGMethod m,
    ITestNGMethod[] methods)
{
  String canonicalMethodName = calculateMethodCanonicalName(m);
  List<ITestNGMethod> vResult = Lists.newArrayList();
  String regexp = null;
  for (String fullyQualifiedRegexp : m.getMethodsDependedUpon()) {
    boolean foundAtLeastAMethod = false;

    if (null != fullyQualifiedRegexp) {
      // Escapes $ in regexps as it is not meant for end - line matching, but inner class matches.
      regexp = fullyQualifiedRegexp.replace("$", "\\$");
      boolean usePackage = regexp.indexOf('.') != -1;
      Pattern pattern = Pattern.compile(regexp);

      for (ITestNGMethod method : methods) {
        ConstructorOrMethod thisMethod = method.getConstructorOrMethod();
        String thisMethodName = thisMethod.getName();
        String methodName = usePackage ?
            calculateMethodCanonicalName(method)
            : thisMethodName;
        Pair<String, String> cacheKey = Pair.create(regexp, methodName);
        Boolean match = MATCH_CACHE.get(cacheKey);
        if (match == null) {
            match = pattern.matcher(methodName).matches();
            MATCH_CACHE.put(cacheKey, match);
        }
        if (match) {
          vResult.add(method);
          foundAtLeastAMethod = true;
        }
      }
    }

    if (!foundAtLeastAMethod) {
      if (m.ignoreMissingDependencies()) {
        continue;
      }
      if (m.isAlwaysRun()) {
        continue;
      }
      Method maybeReferringTo = findMethodByName(m, regexp);
      if (maybeReferringTo != null) {
        throw new TestNGException(canonicalMethodName + "() is depending on method "
            + maybeReferringTo + ", which is not annotated with @Test or not included.");
      }
      throw new TestNGException(canonicalMethodName
          + "() depends on nonexistent method " + regexp);
    }
  }//end for

  return vResult.toArray(new ITestNGMethod[vResult.size()]);
}