Package org.testng

Examples of org.testng.ITestNGMethod


  {
    List<ITestResult> testNGTestResults = TestNGTAPUtils.getTestNGResultsOrderedByExecutionDate(resultMap);
   
    for ( ITestResult testResult : testNGTestResults )
    {
      ITestNGMethod method = testResult.getMethod();
     
      List<ITestResult> testResultsForThisMethod = testResultsPerMethod.get( method );
     
      if ( testResultsForThisMethod == null )
      {
        testResultsForThisMethod = new ArrayList<ITestResult>();
        testResultsPerMethod.put(method, testResultsForThisMethod);
      }
      testResultsForThisMethod.add( testResult );
    }
   
   
    Set<ITestNGMethod> keySet = testResultsPerMethod.keySet();
   
    for( ITestNGMethod method : keySet )
    {
      TestSet testSet = new TestSet();
     
      List<ITestResult> testResults = testResultsPerMethod.get( method );
      testSet.setPlan( new Plan(testResults.size()) );
     
      for ( ITestResult testResult : testResults )
      {
        TestResult tapTestResult = TestNGTAPUtils.generateTAPTestResult( testResult, testSet.getNumberOfTestResults()+1 );
        testSet.addTestResult( tapTestResult );
      }

      File output = new File(testContext.getOutputDirectory(), method.getTestClass().getName()+"#"+method.getMethodName()+".tap");
      tapProducer.dump(testSet, output);
   
  }
View Full Code Here


      {
        List<ITestResult> testResults = TestNGTAPUtils.getTestNGResultsOrderedByExecutionDate(suiteResult.getTestContext());
       
        for(ITestResult testResult : testResults)
        {
          ITestNGMethod method = testResult.getMethod();
         
          String[] groupsNm = findInWhatGroupsMethodIs(method, groups);
         
          for(String gpNm : groupsNm)
          {
View Full Code Here

    addAll( total, results.get("skipped") );
   
    ITestNGMethod[] allMethodsInCtx = testContext.getAllTestMethods();
    for (int i = 0; i < allMethodsInCtx.length; i++)
    {
      ITestNGMethod methodInCtx = allMethodsInCtx [ i ];
     
      Collection<ITestNGMethod> allMethodsFound = total.getAllMethods();
      boolean exists = false;
      for( ITestNGMethod methodFound : allMethodsFound )
      {
        if ( methodInCtx.getTestClass().getName().equals(methodFound.getTestClass().getName()))
        {
          if ( methodInCtx.getMethod().getName().equals(methodFound.getMethod().getName()))
          {
            exists = true;
          }
        }
      }
      if ( ! exists )
      {
        ITestResult skippedTestResult =
          new org.testng.internal.TestResult(methodInCtx.getTestClass(), methodInCtx.getInstances(), methodInCtx, null, testContext.getStartDate().getTime(), testContext.getEndDate().getTime());
        skippedTestResult.setStatus(ITestResult.SKIP);
        total.addResult(skippedTestResult, methodInCtx);
      }
    }
   
View Full Code Here

    {
      Object o = ctx.getAttribute(attr);
      if ( o instanceof TAPAttribute )
      {
        TAPAttribute tapAttr = (TAPAttribute)o;
        ITestNGMethod testNGMethod = tr.getMethod();
        Method method = testNGMethod.getMethod();
        if ( method == tapAttr.getMethod() )
        {
          tr.setAttribute(attr, tapAttr.getValue());
        }
      }
View Full Code Here

   * validates that the failed invoc number are the correct ones, ie the prime numbers.
   * @param ctx
   */
  @AfterClass(alwaysRun=true)
  public void check(ITestContext ctx){
    ITestNGMethod testMethod = getMethod(ctx, "isNotPrime");

    List<Integer> failed = testMethod.getFailedInvocationNumbers();
    if (failed.size() != primes.size()){
      throw new Error();
    }
    for (Integer num : primes) {
      Assert.assertTrue(failed.contains(num),num+" should be present to be retried.It is not.");
View Full Code Here



  private ITestNGMethod getMethod(ITestContext ctx, String methodName) {

    ITestNGMethod method = null;
    for (int i = 0; i < ctx.getAllTestMethods().length; i++) {
      method = ctx.getAllTestMethods()[i];
      if (method.getMethodName().equals(methodName)) {
        return method;
      }
    }
    throw new RuntimeException("test case creation bug.");
  }
View Full Code Here

      ITestContext context) {

    List<IMethodInstance> result = new ArrayList<IMethodInstance>();
    Map<Class<?>, List<IMethodInstance>> verifyMethods = Maps.newHashMap();
    for (IMethodInstance mi : methods) {
      ITestNGMethod tm = mi.getMethod();
      List<IMethodInstance> verify = verifyMethods.get(tm.getRealClass());
      if (verify == null) {
        verify = findVerifyMethods(tm.getRealClass(), tm);
      }
      result.add(mi);
      result.addAll(verify);
    }
View Full Code Here

  private List<IMethodInstance> findVerifyMethods(Class realClass, final ITestNGMethod tm) {
    List<IMethodInstance> result = new ArrayList<IMethodInstance>();
    for (final Method m : realClass.getDeclaredMethods()) {
      Annotation a = m.getAnnotation(Verify.class);
      if (a != null) {
        final ITestNGMethod vm = TestNGUtils.createITestNGMethod(tm, m);
        result.add(new IMethodInstance() {

          @Override
          public Object[] getInstances() {
            return tm.getInstances();
View Full Code Here


    private IMethodInstance mockIMethodAnnotatedWith(Class methodClass, boolean firstTestAnnotation,
                                                     boolean lastTestAnnotation, boolean orderAnnotation) throws Exception {
        IMethodInstance methodInstance = mock(IMethodInstance.class);
        ITestNGMethod testNgMethod = mock(ITestNGMethod.class);

        when(methodInstance.getMethod()).thenReturn(testNgMethod);
        when(testNgMethod.getRealClass()).thenReturn(methodClass);

        String methodName;
        if (firstTestAnnotation && lastTestAnnotation && orderAnnotation == true) {
            methodName = ClassWithMethodsToTest.WITH_TEST_ORDER_ONE_AND_FIRST_AND_LAST_ANNOTATION;
        } else if (firstTestAnnotation && lastTestAnnotation && orderAnnotation == false) {
            methodName = ClassWithMethodsToTest.WITH_FIRST_AND_LAST_ANNOTATION;
        } else if (firstTestAnnotation && orderAnnotation == true) {
            methodName = ClassWithMethodsToTest.WITH_TEST_ORDER_ONE_AND_FIRST_TEST;
        }
        else if (firstTestAnnotation && orderAnnotation == false) {
            methodName = ClassWithMethodsToTest.WITH_FIRST_TEST_ANNOTATION;
        }
        else if (lastTestAnnotation && orderAnnotation == true) {
            methodName = ClassWithMethodsToTest.WITH_TEST_ORDER_ONE_AND_LAST_TEST;
        }
        else if (lastTestAnnotation && orderAnnotation == false) {
            methodName = ClassWithMethodsToTest.WITH_LAST_TEST_ANNOTATION;
        }
        else if(orderAnnotation == true) {
            methodName = ClassWithMethodsToTest.WITH_TEST_ORDER_ONE;
        }
        else {
            methodName = ClassWithMethodsToTest.WITHOUT_ANNOTATIONS;
        }

        mockWithMethod(testNgMethod, methodName);

        when(testNgMethod.getMethodsDependedUpon()).thenReturn(new String[]{});
        return methodInstance;
    }
View Full Code Here

        return mockIMethodDependantUponOtherMethods(ClassWithMethodsToTest.class);
    }

    private IMethodInstance mockIMethodDependantUponOtherMethods(Class methodClass) throws Exception {
        IMethodInstance methodInstance = mock(IMethodInstance.class);
        ITestNGMethod testNgMethod = mock(ITestNGMethod.class);

        when(methodInstance.getMethod()).thenReturn(testNgMethod);
        when(testNgMethod.getRealClass()).thenReturn(methodClass);
        when(testNgMethod.getMethodsDependedUpon()).thenReturn(new String[]{"method1, method2"});


        Method methodWithoutAnnotations = ClassWithMethodsToTest.class.getMethod(ClassWithMethodsToTest.WITHOUT_ANNOTATIONS);
        when(testNgMethod.getMethod()).thenReturn(methodWithoutAnnotations);
        when(testNgMethod.getMethodName()).thenReturn(ClassWithMethodsToTest.METHOD_DEPENDANT_UPON_OTHER_METHODS);


        return methodInstance;
    }
View Full Code Here

TOP

Related Classes of org.testng.ITestNGMethod

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.