Пример #1
0
  private static Method findDataProvider(Class clazz, Method m, IAnnotationFinder finder) {
    Method result = null;
    String dataProviderName = null;
    Class dataProviderClass = null;

    ITestAnnotation annotation = AnnotationHelper.findTest(finder, m);
    if (annotation != null) {
      dataProviderName = annotation.getDataProvider();
      dataProviderClass = annotation.getDataProviderClass();
    }

    if (dataProviderName == null) {
      IFactoryAnnotation factory = AnnotationHelper.findFactory(finder, m);
      if (factory != null) {
        dataProviderName = factory.getDataProvider();
        dataProviderClass = null;
      }
    }

    if (null != dataProviderName && !"".equals(dataProviderName)) {
      result = findDataProvider(clazz, finder, dataProviderName, dataProviderClass);

      if (null == result) {
        throw new TestNGException(
            "Method "
                + m
                + " requires a @DataProvider named : "
                + dataProviderName
                + (dataProviderClass != null ? " in class " + dataProviderClass.getName() : ""));
      }
    }

    return result;
  }
Пример #2
0
  @Override
  public void transform(
      ITestAnnotation testannotation,
      Class testClass,
      Constructor testConstructor,
      Method testMethod) {
    IRetryAnalyzer retry = testannotation.getRetryAnalyzer();

    if (retry == null) {
      testannotation.setRetryAnalyzer(Retry.class);
    }
  }
Пример #3
0
  @Test(groups = "current")
  public void verifyTestEnabledInheritance() throws SecurityException, NoSuchMethodException {
    {
      Method method = MTest3.class.getMethod("enabled1", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertFalse(test1.getEnabled());
    }

    {
      Method method = MTest3.class.getMethod("enabled2", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertTrue(test1.getEnabled());
    }
  }
Пример #4
0
  @Test
  public void verifyTestDependsOnGroupsInheritance()
      throws SecurityException, NoSuchMethodException {
    {
      Method method = MTest3.class.getMethod("dependsOnGroups1", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertEqualsNoOrder(new String[] {"dog2", "dog1", "dog3"}, test1.getDependsOnGroups());
    }

    {
      Method method = MTest3.class.getMethod("dependsOnGroups2", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertEqualsNoOrder(new String[] {"dog1", "dog3"}, test1.getDependsOnGroups());
    }
  }
Пример #5
0
 public void transform(
     ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
   if (testMethod != null) {
     super.transform(annotation, testClass, testConstructor, testMethod);
     int invocationCount = createConfiguration(testMethod.getDeclaringClass(), testMethod);
     annotation.setInvocationCount(invocationCount);
   }
 }
Пример #6
0
  @Test
  public void verifyTestGroupsInheritance() throws SecurityException, NoSuchMethodException {
    {
      Method method = MTest3.class.getMethod("groups1", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertEqualsNoOrder(
          new String[] {"method-test3", "child-class-test3", "base-class"}, test1.getGroups());
    }

    {
      Method method = MTest3.class.getMethod("groups2", new Class[0]);
      ITestAnnotation test1 =
          (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
      Assert.assertEqualsNoOrder(
          new String[] {"child-class-test3", "base-class"}, test1.getGroups());
    }
  }
Пример #7
0
 @Override
 @SuppressWarnings("rawtypes")
 public void transform(
     ITestAnnotation annotation,
     Class testClass,
     Constructor testConstructor,
     Method testMethod) {
   if (!annotation.getEnabled()) {
     return;
   }
   if (testMethod == null) {
     return;
   }
   String className = testMethod.getDeclaringClass().getName();
   String methodName = testMethod.getName();
   TestDescription testDescription = new TestDescription(className, methodName);
   boolean isIncluded = testSelectorList.isIncluded(testDescription);
   annotation.setEnabled(isIncluded && !isDryRun);
 }
Пример #8
0
  private void init() {
    IAnnotation a = AnnotationHelper.findConfiguration(m_annotationFinder, m_method.getMethod());
    IConfigurationAnnotation annotation = (IConfigurationAnnotation) a;
    if (a != null) {
      m_inheritGroupsFromTestClass = annotation.getInheritGroups();
      setEnabled(annotation.getEnabled());
      setDescription(annotation.getDescription());
    }

    if (annotation != null && annotation.isFakeConfiguration()) {
      if (annotation.getBeforeSuite()) {
        initGroups(IBeforeSuite.class);
      }
      if (annotation.getAfterSuite()) {
        initGroups(IAfterSuite.class);
      }
      if (annotation.getBeforeTest()) {
        initGroups(IBeforeTest.class);
      }
      if (annotation.getAfterTest()) {
        initGroups(IAfterTest.class);
      }
      if (annotation.getBeforeGroups().length != 0) {
        initGroups(IBeforeGroups.class);
      }
      if (annotation.getAfterGroups().length != 0) {
        initGroups(IAfterGroups.class);
      }
      if (annotation.getBeforeTestClass()) {
        initGroups(IBeforeClass.class);
      }
      if (annotation.getAfterTestClass()) {
        initGroups(IAfterClass.class);
      }
      if (annotation.getBeforeTestMethod()) {
        initGroups(IBeforeMethod.class);
      }
      if (annotation.getAfterTestMethod()) {
        initGroups(IAfterMethod.class);
      }
    } else {
      initGroups(IConfigurationAnnotation.class);
    }

    // If this configuration method has inherit-groups=true, add the groups
    // defined in the @Test class
    if (inheritGroupsFromTestClass()) {
      ITestAnnotation classAnnotation =
          (ITestAnnotation) m_annotationFinder.findAnnotation(m_methodClass, ITestAnnotation.class);
      if (classAnnotation != null) {
        String[] groups = classAnnotation.getGroups();
        Map<String, String> newGroups = Maps.newHashMap();
        for (String g : getGroups()) {
          newGroups.put(g, g);
        }
        if (groups != null) {
          for (String g : groups) {
            newGroups.put(g, g);
          }
          setGroups(newGroups.values().toArray(new String[newGroups.size()]));
        }
      }
    }

    if (annotation != null) {
      setTimeOut(annotation.getTimeOut());
    }
  }