Package org.jboss.arquillian.test.spi

Examples of org.jboss.arquillian.test.spi.TestResult


      return new Statement()
      {
         @Override
         public void evaluate() throws Throwable
         {
            TestResult result = State.getTestAdaptor().test(new TestMethodExecutor()
            {
               @Override
               public void invoke(Object... parameters) throws Throwable
               {
                  try
                  {
                     method.invokeExplosively(test, parameters);
                  }
                  catch (Throwable e)
                  {
                     // Force a way to return the thrown Exception from the Container the client.
                     State.caughtTestException(e);
                     throw e;
                  }
               }
              
               public Method getMethod()
               {
                  return method.getMethod();
               }
              
               public Object getInstance()
               {
                  return test;
               }
            });
            if(result.getThrowable() != null)
            {
               throw result.getThrowable();
            }
         }
      };
   }
View Full Code Here


      return Collections.emptyList();
   }

   public TestResult execute(Class<?> testClass, String methodName)
   {
      TestResult testResult = new TestResult(Status.PASSED);
      ExpectedExceptionHolder exceptionHolder = new ExpectedExceptionHolder();
      try
      {
          JUnitCore runner = new JUnitCore();

          runner.addListener(exceptionHolder);

          for (RunListener listener : getRunListeners())
             runner.addListener(listener);

          Result result = runner.run(Request.method(testClass, methodName));
          testResult.setThrowable(exceptionHolder.getException());

          if (result.getFailureCount() > 0)
          {
             testResult.setStatus(Status.FAILED);
             testResult.setThrowable(result.getFailures().get(0).getException());
          }
          if (result.getIgnoreCount() > 0)
          {
              testResult.setStatus(Status.SKIPPED);
          }
      }
      catch (Throwable th) {
          testResult.setStatus(Status.FAILED);
          testResult.setThrowable(th);
      }
      finally
      {
          testResult.setEnd(System.currentTimeMillis());
      }
      return testResult;
   }
View Full Code Here

         if (testInstance != null)
         {
            try
            {
               TestResult result = null;
               try
               {
                  try
                  {
                     testInstance = ClassLoaderAdapterBuilder.callingLoader(getClass().getClassLoader())
                              .delegateLoader(testInstance.getClass().getClassLoader())
                              .enhance(testInstance, testClass);
                  }
                  catch (Exception e)
                  {
                     System.out.println("Could not enhance test class. Falling back to un-proxied invocation.");
                  }

                  Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
                  Annotation[] annotations = method.getAnnotations();

                  for (Annotation annotation : annotations)
                  {
                     if ("org.junit.Ignore".equals(annotation.getClass().getName()))
                     {
                        result = new TestResult(Status.SKIPPED);
                     }
                  }

                  if (result == null)
                  {
                     try
                     {
                        System.out.println("Executing test method: "
                                 + testMethodExecutor.getInstance().getClass().getName() + "."
                                 + testMethodExecutor.getMethod().getName() + "()");

                        try
                        {
                           invokeBefore(testInstance.getClass(), testInstance);
                           method.invoke(testInstance);
                        }
                        catch (Exception e)
                        {
                           throw e;
                        }
                        finally
                        {
                           invokeAfter(testInstance.getClass(), testInstance);
                        }

                        result = new TestResult(Status.PASSED);
                     }
                     catch (InvocationTargetException e)
                     {
                        if (e.getCause() != null && e.getCause() instanceof Exception)
                           throw (Exception) e.getCause();
                        else
                           throw e;
                     }
                  }
               }
               catch (AssertionError e)
               {
                  result = new TestResult(Status.FAILED, e);
               }
               catch (Exception e)
               {
                  result = new TestResult(Status.FAILED, e);

                  Throwable cause = e.getCause();
                  while (cause != null)
                  {
                     if (cause instanceof AssertionError)
                     {
                        result = new TestResult(Status.FAILED, cause);
                        break;
                     }
                     cause = cause.getCause();
                  }
               }
View Full Code Here

    * @see org.spockframework.runtime.extension.AbstractMethodInterceptor#interceptFeatureMethod(org.spockframework.runtime.extension.IMethodInvocation)
    */
   @Override
   public void interceptFeatureMethod(final IMethodInvocation invocation) throws Throwable
   {
      TestResult result = testRunner.test(new TestMethodExecutor()
      {
         public Method getMethod()
         {
            return invocation.getFeature().getFeatureMethod().getReflection();
         }
        
         public Object getInstance()
         {
            return invocation.getTarget();
         }

         public void invoke(Object... parameters) throws Throwable
         {
              invocation.proceed();
         }
      });
     
      if(result.getThrowable() != null)
      {
         throw result.getThrowable();
      }
   }
View Full Code Here

   @Inject @TestScoped
   private InstanceProducer<TestResult> testResult;

   public void execute(@Observes Test event) throws Exception
   {
      TestResult result = new TestResult();
      try
      {
         event.getTestMethodExecutor().invoke(
               enrichArguments(
                     event.getTestMethod(),
                     serviceLoader.get().all(TestEnricher.class)));
         result.setStatus(Status.PASSED);
      }
      catch (Throwable e)
      {
         result.setStatus(Status.FAILED);
         result.setThrowable(e);
      }
      finally
      {
         result.setEnd(System.currentTimeMillis());
      }
      testResult.set(result);
   }
View Full Code Here

      return new Statement()
      {
         @Override
         public void evaluate() throws Throwable
         {
            TestResult result = State.getTestAdaptor().test(new TestMethodExecutor()
            {
               @Override
               public void invoke(Object... parameters) throws Throwable
               {
                  try
                  {
                     method.invokeExplosively(test, parameters);
                  }
                  catch (Throwable e)
                  {
                     // Force a way to return the thrown Exception from the Container the client.
                     State.caughtTestException(e);
                     throw e;
                  }
               }
              
               public Method getMethod()
               {
                  return method.getMethod();
               }
              
               public Object getInstance()
               {
                  return test;
               }
            });
            if (result != null && result.getThrowable() != null)
            {
               throw result.getThrowable();
            }
         }
      };
   }
View Full Code Here

   @Inject @TestScoped
   private InstanceProducer<TestResult> testResult;
  
   public void execute(@Observes Test event) throws Exception
   {
      TestResult result = new TestResult();
      try
      {
         event.getTestMethodExecutor().invoke(
               enrichArguments(
                     event.getTestMethod(),
                     serviceLoader.get().all(TestEnricher.class)));
         result.setStatus(Status.PASSED);
      }
      catch (Throwable e)
      {
         result.setStatus(Status.FAILED);
         result.setThrowable(e);
      }
      finally
      {
         result.setEnd(System.currentTimeMillis());        
      }
      testResult.set(result);
   }
View Full Code Here

        Mockito.when(configuration.getScreenshotType()).thenReturn("PNG");

        fire(new ScreenshooterExtensionConfigured());
        fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        bind(TestScoped.class, TestResult.class, new TestResult(Status.PASSED));

        fire(new After(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        assertEventFired(BeforeScreenshotTaken.class, 1);
        assertEventFired(TakeScreenshot.class, 1);
View Full Code Here

        Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(false);

        fire(new ScreenshooterExtensionConfigured());
        fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        bind(TestScoped.class, TestResult.class, new TestResult(Status.FAILED));

        fire(new After(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        assertEventFired(BeforeScreenshotTaken.class, 1);
        assertEventFired(TakeScreenshot.class, 1);
View Full Code Here

        Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(true);

        fire(new ScreenshooterExtensionConfigured());
        fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        bind(TestScoped.class, TestResult.class, new TestResult(Status.FAILED));

        fire(new After(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

        assertEventFired(BeforeScreenshotTaken.class, 1);
        assertEventFired(TakeScreenshot.class, 1);
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.test.spi.TestResult

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.