org.testng.internal.ConstructorOrMethod Java Examples

The following examples show how to use org.testng.internal.ConstructorOrMethod. 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: TestClass.java    From qaf with MIT License 6 votes vote down vote up
/**
 * Create the test methods that belong to this class (rejects
 * all those that belong to a different class).
 */
private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) {
  List<ITestNGMethod> vResult = Lists.newArrayList();
  for (ITestNGMethod tm : methods) {
    ConstructorOrMethod m = tm.getConstructorOrMethod();
    if (m.getDeclaringClass().isAssignableFrom(m_testClass)) {
      for (Object o : m_iClass.getInstances(false)) {
        log(4, "Adding method " + tm + " on TestClass " + m_testClass);
        vResult.add(new TestNGScenario(/* tm.getRealClass(), */ m.getMethod(), m_annotationFinder, m_xmlTest,
            o));
      }
    }
    else {
      log(4, "Rejecting method " + tm + " for TestClass " + m_testClass);
    }
  }

  ITestNGMethod[] result = vResult.toArray(new ITestNGMethod[vResult.size()]);
  return result;
}
 
Example #2
Source File: BaseTest.java    From video-recorder-java with MIT License 6 votes vote down vote up
protected ITestResult prepareMock(Class<?> tClass, Method method) {
  ITestResult result = mock(ITestResult.class);
  IClass clazz = mock(IClass.class);
  ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
  ConstructorOrMethod cm = mock(ConstructorOrMethod.class);
  String methodName = method.getName();
  when(result.getTestClass()).thenReturn(clazz);
  when(result.getTestClass().getRealClass()).thenReturn(tClass);
  when(clazz.getName()).thenReturn(this.getClass().getName());
  when(result.getMethod()).thenReturn(testNGMethod);
  when(cm.getMethod()).thenReturn(method);
  when(result.getMethod().getConstructorOrMethod()).thenReturn(cm);
  when(testNGMethod.getMethodName()).thenReturn(methodName);
  ITestContext context = mock(ITestContext.class);
  when(result.getTestContext()).thenReturn(context);
  XmlTest xmlTest = new XmlTest();
  XmlSuite suite = new XmlSuite();
  xmlTest.setXmlSuite(suite);
  suite.setListeners(Arrays.asList(VideoListener.class.getName()));
  when(context.getCurrentXmlTest()).thenReturn(xmlTest);
  return result;
}
 
Example #3
Source File: TestNGAop.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    for (IMethodInstance methodIns : methods) {
        ITestNGMethod method = methodIns.getMethod();
        ConstructorOrMethod meth = method.getConstructorOrMethod();
        Method m = meth.getMethod();
        if (m != null) {
            DB db = m.getAnnotation(DB.class);
            if (db != null) {
                TransactionLegacy txn = TransactionLegacy.open(m.getName());
            }
        }
    }

    // TODO Auto-generated method stub
    return methods;
}
 
Example #4
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    testngListener = spy(new AllureTestListener());
    allure = mock(Allure.class);

    testngListener.setLifecycle(allure);

    ISuite suite = mock(ISuite.class);
    when(suite.getName()).thenReturn(DEFAULT_SUITE_NAME);
    XmlTest xmlTest = mock(XmlTest.class);
    when(xmlTest.getName()).thenReturn(DEFAULT_XML_TEST_NAME);
    testContext = mock(ITestContext.class);
    when(testContext.getSuite()).thenReturn(suite);
    when(testContext.getCurrentXmlTest()).thenReturn(xmlTest);

    // mocking test method parameters
    ConstructorOrMethod constructorOrMethod = mock(ConstructorOrMethod.class);
    when(constructorOrMethod.getMethod()).thenReturn(parametrizedTestMethod(0, null, null, null));
    method = mock(ITestNGMethod.class);
    when(method.getConstructorOrMethod()).thenReturn(constructorOrMethod);
    testResult = mock(ITestResult.class);
    when(testResult.getMethod()).thenReturn(method);
    when(testResult.getParameters()).thenReturn(new Object[]{});
    IClass iClass = mock(IClass.class);
    when(testResult.getTestClass()).thenReturn(iClass);
}
 
Example #5
Source File: AllureTestNg.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private Optional<Method> getMethod(final ITestNGMethod method) {
    return Optional.ofNullable(method)
            .map(ITestNGMethod::getConstructorOrMethod)
            .map(ConstructorOrMethod::getMethod);
}
 
Example #6
Source File: VerboseReporter.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param method method to be described
 * @return FQN of a class + method declaration for a method passed in
 *      ie. test.triangle.CheckCount.testCheckCount(java.lang.String)
 */
private String getMethodDeclaration(ITestNGMethod method) {
    //see Utils.detailedMethodName
    //perhaps should rather adopt the original method instead
    ConstructorOrMethod m = method.getConstructorOrMethod();
    StringBuilder buf = new StringBuilder();
    buf.append("\"");
    if (suiteName != null) {
        buf.append(suiteName);
    } else {
        buf.append("UNKNOWN");
    }
    buf.append("\"");
    buf.append(" - ");
    if (method.isBeforeSuiteConfiguration()) {
        buf.append("@BeforeSuite ");
    } else if (method.isBeforeTestConfiguration()) {
        buf.append("@BeforeTest ");
    } else if (method.isBeforeClassConfiguration()) {
        buf.append("@BeforeClass ");
    } else if (method.isBeforeGroupsConfiguration()) {
        buf.append("@BeforeGroups ");
    } else if (method.isBeforeMethodConfiguration()) {
        buf.append("@BeforeMethod ");
    } else if (method.isAfterMethodConfiguration()) {
        buf.append("@AfterMethod ");
    } else if (method.isAfterGroupsConfiguration()) {
        buf.append("@AfterGroups ");
    } else if (method.isAfterClassConfiguration()) {
        buf.append("@AfterClass ");
    } else if (method.isAfterTestConfiguration()) {
        buf.append("@AfterTest ");
    } else if (method.isAfterSuiteConfiguration()) {
        buf.append("@AfterSuite ");
    }
    buf.append(m.getDeclaringClass().getName());
    buf.append(".");
    buf.append(m.getName());
    buf.append("(");
    int i = 0;
    for (Class<?> p : m.getParameterTypes()) {
        if (i++ > 0) {
            buf.append(", ");
        }
        buf.append(p.getName());
    }
    buf.append(")");
    return buf.toString();
}