Examples of ITestResult


Examples of org.testng.ITestResult

    for(ITestNGMethod tm : methods) {
      if(null == testClass) {
        testClass= tm.getTestClass();
      }

      ITestResult testResult= new TestResult(testClass,
                                             instance,
                                             tm,
                                             null,
                                             System.currentTimeMillis(),
                                             System.currentTimeMillis());

      IConfiguration configurationAnnotation= null;
      try {
        Object[] instances= tm.getInstances();
        if (instances == null || instances.length == 0) instances = new Object[] { instance };
        Class<?> objectClass= instances[0].getClass();
        Method method= tm.getMethod();

        // Only run the configuration if
        // - the test is enabled and
        // - the Configuration method belongs to the same class or a parent
        if(MethodHelper.isEnabled(objectClass, m_annotationFinder)) {
          configurationAnnotation= (IConfiguration) AnnotationHelper.findConfiguration(m_annotationFinder, method);

          boolean isClassConfiguration= isClassConfiguration(configurationAnnotation);
          boolean alwaysRun= isAlwaysRun(configurationAnnotation);

          if(!confInvocationPassed(tm) && !alwaysRun) {
            handleConfigurationSkip(tm, testResult);
            continue;
          }

          log(3, "Invoking " + Utils.detailedMethodName(tm, true));
         
          Object[] parameters= Parameters.createConfigurationParameters(tm.getMethod(),
                                                                        params,
                                                                        currentTestMethod,
                                                                        m_annotationFinder,
                                                                        suite,
                                                                        m_testContext);
          testResult.setParameters(parameters);

          Object[] newInstances= (null != instance) ? new Object[] { instance } : instances;

          invokeConfigurationMethod(newInstances, tm, parameters, isClassConfiguration, testResult);
         
          // TODO: probably we should trigger the event for each instance???
          testResult.setEndMillis(System.currentTimeMillis());
          runConfigurationListeners(testResult);
        } // if is enabled
        else {
          log(3,
              "Skipping "
View Full Code Here

Examples of org.testng.ITestResult

      } // okToProceed
      else {
        //
        // Test is being skipped
        //
        ITestResult testResult= new TestResult(testClass, null,
                                               testMethod,
                                               null,
                                               start,
                                               System.currentTimeMillis());
        testResult.setEndMillis(System.currentTimeMillis());
        String missingGroup = testMethod.getMissingGroup();
        if (missingGroup != null) {
          testResult.setThrowable(new Throwable("Method " + testMethod
              + " depends on nonexistent group \"" + missingGroup + "\""));
        }

        testResult.setStatus(ITestResult.SKIP);
        m_notifier.addSkippedTest(testMethod, testResult);
        runTestListeners(testResult);
      }
    }
   
View Full Code Here

Examples of org.testng.ITestResult

    // Go through all the results and create a TestResult for each of them
    //
    List<ITestResult> resultsToRetry = new ArrayList<ITestResult>();

    for (int i = 0; i < result.size(); i++) {
      ITestResult testResult = result.get(i);
      Throwable ite= testResult.getThrowable();
      int status= testResult.getStatus();

      // Exception thrown?
      if(ite != null) {

        //  Invocation caused an exception, see if the method was annotated with @ExpectedException
        if(isExpectedException(ite, expectedExceptionClasses)) {
          testResult.setStatus(ITestResult.SUCCESS);
          status= ITestResult.SUCCESS;
        }
        else if (SkipException.class.isAssignableFrom(ite.getClass())){
          SkipException skipEx= (SkipException) ite;
          if(skipEx.isSkip()) {
            status= ITestResult.SKIP;
          }
          else {
            handleException(ite, testMethod, testResult, failureCount++);
            status= ITestResult.FAILURE;
          }
        }
        else {
          handleException(ite, testMethod, testResult, failureCount++);
          status= testResult.getStatus();
        }
      }

      // No exception thrown, make sure we weren't expecting one
      else if(status != ITestResult.SKIP) {
        if (expectedExceptionClasses.length > 0) {
          testResult.setThrowable(
              new TestException("Expected an exception in test method " + testMethod));
          status= ITestResult.FAILURE;
        }
      }

      testResult.setStatus(status);

      boolean retry = false;
     
      if (testResult.getStatus() == ITestResult.FAILURE) {
        IRetryAnalyzer retryAnalyzer = testMethod.getRetryAnalyzer();

        if (retryAnalyzer != null) {
          retry = retryAnalyzer.retry(testResult);
        }

        if (retry) {
          resultsToRetry.add(testResult);
          if (failedInstances != null) {
            failedInstances.add(testResult.getMethod().getInstances()[i]);
          }
        }
      }
      if (!retry) {
        // Collect the results
View Full Code Here

Examples of org.testng.ITestResult

    for(ITestNGMethod tm : methods) {
      if(null == testClass) {
        testClass= tm.getTestClass();
      }

      ITestResult testResult= new TestResult(testClass,
                                             instance,
                                             tm,
                                             null,
                                             System.currentTimeMillis(),
                                             System.currentTimeMillis(),
                                             m_testContext);

      IConfigurationAnnotation configurationAnnotation= null;
      try {
        Object[] instances= tm.getInstances();
        if (instances == null || instances.length == 0) {
          instances = new Object[] { instance };
        }
        Class<?> objectClass= instances[0].getClass();
        Method method= tm.getMethod();

        // Only run the configuration if
        // - the test is enabled and
        // - the Configuration method belongs to the same class or a parent
        if(MethodHelper.isEnabled(objectClass, m_annotationFinder)) {
          configurationAnnotation = AnnotationHelper.findConfiguration(m_annotationFinder, method);

          if (MethodHelper.isEnabled(configurationAnnotation)) {
            boolean isClassConfiguration = isClassConfiguration(configurationAnnotation);
            boolean isSuiteConfiguration = isSuiteConfiguration(configurationAnnotation);
            boolean alwaysRun= isAlwaysRun(configurationAnnotation);

            if (!confInvocationPassed(tm, currentTestMethod, testClass, instance) && !alwaysRun) {
              handleConfigurationSkip(tm, testResult, configurationAnnotation, currentTestMethod, instance, suite);
              continue;
            }

            log(3, "Invoking " + Utils.detailedMethodName(tm, true));

            Object[] parameters = Parameters.createConfigurationParameters(tm.getMethod(),
                params,
                parameterValues,
                currentTestMethod,
                m_annotationFinder,
                suite,
                m_testContext,
                testMethodResult);
            testResult.setParameters(parameters);

            Object[] newInstances= (null != instance) ? new Object[] { instance } : instances;

            runConfigurationListeners(testResult, true /* before */);

            invokeConfigurationMethod(newInstances, tm,
              parameters, isClassConfiguration, isSuiteConfiguration, testResult);

            // TODO: probably we should trigger the event for each instance???
            testResult.setEndMillis(System.currentTimeMillis());
            runConfigurationListeners(testResult, false /* after */);
          }
          else {
            log(3,
                "Skipping "
View Full Code Here

Examples of org.testng.ITestResult

      if (!okToProceed) {
        //
        // Not okToProceed. Test is being skipped
        //
        ITestResult testResult = new TestResult(testClass, null /* instance */,
                                               testMethod,
                                               null /* cause */,
                                               start,
                                               System.currentTimeMillis(),
                                               m_testContext);
        String missingGroup = testMethod.getMissingGroup();
        if (missingGroup != null) {
          testResult.setThrowable(new Throwable("Method " + testMethod
              + " depends on nonexistent group \"" + missingGroup + "\""));
        }

        testResult.setStatus(ITestResult.SKIP);
        result.add(testResult);
        m_notifier.addSkippedTest(testMethod, testResult);
        runTestListeners(testResult);
        return result;
      }

      //
      // If threadPoolSize specified, run this method in its own pool thread.
      //
      if (testMethod.getThreadPoolSize() > 1 && testMethod.getInvocationCount() > 1) {
          return invokePooledTestMethods(testMethod, allTestMethods, suite,
              parameters, groupMethods, testContext);
      }
      //
      // No threads, regular invocation
      //
      else {
        ITestNGMethod[] beforeMethods = filterMethods(testClass, testClass.getBeforeTestMethods(),
            CAN_RUN_FROM_CLASS);
        ITestNGMethod[] afterMethods = filterMethods(testClass, testClass.getAfterTestMethods(),
            CAN_RUN_FROM_CLASS);

        Map<String, String> allParameterNames = Maps.newHashMap();
        ParameterBag bag = createParameters(testMethod,
            parameters, allParameterNames, null, suite, testContext, instances[0],
            null);

        if (bag.hasErrors()) {
          failureCount = handleInvocationResults(testMethod,
              bag.errorResults, null, failureCount, expectedExceptionHolder, true,
              true /* collect results */);
          ITestResult tr = registerSkippedTestResult(testMethod, instances[0], start,
              bag.errorResults.get(0).getThrowable());
          result.add(tr);
          continue;
        }

        Iterator<Object[]> allParameterValues = bag.parameterHolder.parameters;
        int parametersIndex = 0;

        try {
          List<TestMethodWithDataProviderMethodWorker> workers = Lists.newArrayList();

          if (bag.parameterHolder.origin == ParameterOrigin.ORIGIN_DATA_PROVIDER &&
              bag.parameterHolder.dataProviderHolder.annotation.isParallel()) {
            while (allParameterValues.hasNext()) {
              Object[] parameterValues = injectParameters(allParameterValues.next(),
                  testMethod.getMethod(), testContext, null /* test result */);
              TestMethodWithDataProviderMethodWorker w =
                new TestMethodWithDataProviderMethodWorker(this,
                    testMethod, parametersIndex,
                    parameterValues, instances, suite, parameters, testClass,
                    beforeMethods, afterMethods, groupMethods,
                    expectedExceptionHolder, testContext, m_skipFailedInvocationCounts,
                    invocationCount, failureCount, m_notifier);
              workers.add(w);
              // testng387: increment the param index in the bag.
              parametersIndex++;
            }
            PoolService ps = PoolService.getInstance();
            List<ITestResult> r = ps.submitTasksAndWait(testMethod, workers);
            result.addAll(r);

          } else {
            while (allParameterValues.hasNext()) {
              Object[] parameterValues = injectParameters(allParameterValues.next(),
                  testMethod.getMethod(), testContext, null /* test result */);

              List<ITestResult> tmpResults = Lists.newArrayList();

              try {
                tmpResults.addAll(invokeTestMethod(instances,
                                                   testMethod,
                                                   parameterValues,
                                                   parametersIndex,
                                                   suite,
                                                   parameters,
                                                   testClass,
                                                   beforeMethods,
                                                   afterMethods,
                                                   groupMethods));
              }
              finally {
                List<Object> failedInstances = Lists.newArrayList();

                failureCount = handleInvocationResults(testMethod, tmpResults,
                    failedInstances, failureCount, expectedExceptionHolder, true,
                    false /* don't collect results */);
                if (failedInstances.isEmpty()) {
                  result.addAll(tmpResults);
                } else {
                  for (int i = 0; i < failedInstances.size(); i++) {
                    List<ITestResult> retryResults = Lists.newArrayList();

                    failureCount =
                     retryFailed(failedInstances.toArray(),
                     i, testMethod, suite, testClass, beforeMethods,
                     afterMethods, groupMethods, retryResults,
                     failureCount, expectedExceptionHolder,
                     testContext, parameters, parametersIndex);
                  result.addAll(retryResults);
                  }
                }

                //
                // If we have a failure, skip all the
                // other invocationCounts
                //
                if (failureCount > 0
                      && (m_skipFailedInvocationCounts
                            || testMethod.skipFailedInvocations())) {
                  while (invocationCount-- > 0) {
                    result.add(registerSkippedTestResult(testMethod, instances[0], start, null));
                  }
                  break;
                }
              }// end finally
              parametersIndex++;
            }
          }
        }
        catch (Throwable cause) {
          ITestResult r =
              new TestResult(testMethod.getTestClass(),
                instances[0],
                testMethod,
                cause,
                start,
                System.currentTimeMillis(),
                m_testContext);
            r.setStatus(TestResult.FAILURE);
            result.add(r);
            runTestListeners(r);
            m_notifier.addFailedTest(testMethod, r);
        } // catch
      }
View Full Code Here

Examples of org.testng.ITestResult

  } // invokeTestMethod

  private ITestResult registerSkippedTestResult(ITestNGMethod testMethod, Object instance,
      long start, Throwable throwable) {
    ITestResult result =
      new TestResult(testMethod.getTestClass(),
        instance,
        testMethod,
        throwable,
        start,
        System.currentTimeMillis(),
        m_testContext);
    result.setStatus(TestResult.SKIP);
    runTestListeners(result);

    return result;
  }
View Full Code Here

Examples of org.testng.ITestResult

    // Go through all the results and create a TestResult for each of them
    //
    List<ITestResult> resultsToRetry = Lists.newArrayList();

    for (int i = 0; i < result.size(); i++) {
      ITestResult testResult = result.get(i);
      Throwable ite= testResult.getThrowable();
      int status= testResult.getStatus();

      // Exception thrown?
      if (ite != null) {

        //  Invocation caused an exception, see if the method was annotated with @ExpectedException
        if (isExpectedException(ite, expectedExceptionsHolder)) {
          if (messageRegExpMatches(expectedExceptionsHolder.messageRegExp, ite)) {
            testResult.setStatus(ITestResult.SUCCESS);
            status= ITestResult.SUCCESS;
          }
          else {
            testResult.setThrowable(
                new TestException("The exception was thrown with the wrong message:" +
                    " expected \"" + expectedExceptionsHolder.messageRegExp + "\"" +
                    " but got \"" + ite.getMessage() + "\"", ite));
            status= ITestResult.FAILURE;
          }
        } else if (SkipException.class.isAssignableFrom(ite.getClass())){
          SkipException skipEx= (SkipException) ite;
          if(skipEx.isSkip()) {
            status = ITestResult.SKIP;
          }
          else {
            handleException(ite, testMethod, testResult, failureCount++);
            status = ITestResult.FAILURE;
          }
        } else if (ite != null && expectedExceptionsHolder != null) {
          testResult.setThrowable(
              new TestException("Expected exception "
                 + expectedExceptionsHolder.expectedClasses[0].getName()
                 + " but got " + ite, ite));
          status= ITestResult.FAILURE;
        } else {
          handleException(ite, testMethod, testResult, failureCount++);
          status= testResult.getStatus();
        }
      }

      // No exception thrown, make sure we weren't expecting one
      else if(status != ITestResult.SKIP && expectedExceptionsHolder != null) {
        Class<?>[] classes = expectedExceptionsHolder.expectedClasses;
        if (classes != null && classes.length > 0) {
          testResult.setThrowable(
              new TestException("Method " + testMethod + " should have thrown an exception of "
                  + expectedExceptionsHolder.expectedClasses[0]));
          status= ITestResult.FAILURE;
        }
      }

      testResult.setStatus(status);

      boolean retry = false;

      if (testResult.getStatus() == ITestResult.FAILURE) {
        IRetryAnalyzer retryAnalyzer = testMethod.getRetryAnalyzer();

        if (retryAnalyzer != null && failedInstances != null) {
          retry = retryAnalyzer.retry(testResult);
        }

        if (retry) {
          resultsToRetry.add(testResult);
          if (failedInstances != null) {
            failedInstances.add(testResult.getInstance());
          }
        }
      }
      if (collectResults) {
        // Collect the results
View Full Code Here

Examples of org.testng.ITestResult

    outputTestProgress(_lastTestObject);

    List<ITestResult> failedTests = getFailedTests();
    StringBuilder failed = new StringBuilder();
    for (int i = 0; i < failedTests.size(); i++) {
      ITestResult failedTest = failedTests.get(i);
      String fqMethod = getFqMethod(failedTest);
      int numFailures = 1;
      // Peek ahead to see if we had multiple failures for the same method
      // In which case, we list it once with a count of the failures.
      while (((i + 1) < failedTests.size()) &&
View Full Code Here

Examples of org.testng.ITestResult

      when(testContext.getCurrentXmlTest()).thenReturn(xmlTest);
    }

    @Test
    public void skipTestFireTestCaseStartedEvent() {
        ITestResult testResult = mock(ITestResult.class);
        when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
        when(testResult.getTestContext()).thenReturn(testContext);
        doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);
        ITestNGMethod method = mock(ITestNGMethod.class);
        when(method.getDescription()).thenReturn(null);
        when(testResult.getMethod()).thenReturn(method);

        testngListener.onTestSkipped(testResult);

        String suiteUid = testngListener.getSuiteUid(testContext);
        verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, DEFAULT_TEST_NAME))));
View Full Code Here

Examples of org.testng.ITestResult

        verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, DEFAULT_TEST_NAME))));
    }

    @Test
    public void skipTestWithThrowable() {
        ITestResult testResult = mock(ITestResult.class);
        Throwable throwable = new NullPointerException();
        when(testResult.getTestContext()).thenReturn(testContext);
        when(testResult.getThrowable()).thenReturn(throwable);
        when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
        ITestNGMethod method = mock(ITestNGMethod.class);
        when(method.getDescription()).thenReturn(null);
        when(testResult.getMethod()).thenReturn(method);
       
        doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

        testngListener.onTestSkipped(testResult);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.