Package org.jboss.arquillian.test.spi

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


{
  
   @Test
   public void shouldReturnTestResult() throws Exception
   {
      MockTestRunner.add(new TestResult(Status.PASSED, null));
     
      ServletMethodExecutor executor = createExecutor();
      TestResult result = executor.invoke(new MockTestExecutor());
     
      Assert.assertEquals(
            "Should have returned a passed test",
            MockTestRunner.wantedResults.getStatus(),
            result.getStatus());
     
      Assert.assertNull(
            "No Exception should have been thrown",
            result.getThrowable());
   }
View Full Code Here


   }
  
   @Test
   public void shouldReturnThrownException() throws Exception
   {
      MockTestRunner.add(new TestResult(Status.FAILED, new Exception().fillInStackTrace()));
     
      ServletMethodExecutor executor = createExecutor();
      TestResult result = executor.invoke(new MockTestExecutor());
     
      Assert.assertEquals(
            "Should have returned a passed test",
            MockTestRunner.wantedResults.getStatus(),
            result.getStatus());
     
      Assert.assertNotNull(
            "Exception should have been thrown",
            result.getThrowable());
     
   }
View Full Code Here

  
   @Test
   public void shouldReturnExceptionWhenMissingTestClassParameter() throws Exception
   {
      URL url = createURL(ServletTestRunner.OUTPUT_MODE_SERIALIZED, null, null);
      TestResult result = (TestResult)TestUtil.execute(url);
     
      Assert.assertEquals(
            "Should have returned a passed test",
            Status.FAILED,
            result.getStatus());
     
      Assert.assertTrue(
            "No Exception should have been thrown",
            result.getThrowable() instanceof IllegalArgumentException);
   }
View Full Code Here

{
   @Test
   public void shouldReturnPassedTest() throws Exception
   {
      JUnitTestRunner runner = new JUnitTestRunner();
      TestResult result = runner.execute(JUnitTestRunnerTestCase.class, "shouldProvidePassingTestToRunner");
     
      Assert.assertNotNull(result);
      Assert.assertEquals(TestResult.Status.PASSED, result.getStatus());
      Assert.assertNull(result.getThrowable());
   }
View Full Code Here

   public void shouldReturnExceptionOnPassedTest() throws Exception
   {
      // Simulate setting the Exception like Arquillian would. This is a JUnit hack to avoid JUnit Swallowing the Exception.
      State.caughtTestException(new IllegalArgumentException());
      JUnitTestRunner runner = new JUnitTestRunner();
      TestResult result = runner.execute(JUnitTestRunnerTestCase.class, "shouldProvideExpectedExceptionToRunner");
     
      Assert.assertNotNull(result);
      Assert.assertEquals(TestResult.Status.PASSED, result.getStatus());
      Assert.assertNotNull(result.getThrowable());
      Assert.assertEquals(IllegalArgumentException.class, result.getThrowable().getClass());
   }
View Full Code Here

   }

   public void run(final IHookCallBack callback, final ITestResult testResult)
   {
      verifyTestRunnerAdaptorHasBeenSet();
      TestResult result;
      try
      {
         result = deployableTest.get().test(new TestMethodExecutor()
         {
            public void invoke(Object... parameters) throws Throwable
            {
               /*
                *  The parameters are stored in the InvocationHandler, so we can't set them on the test result directly.
                *  Copy the Arquillian found parameters to the InvocationHandlers parameters
                */
               copyParameters(parameters, callback.getParameters());
               callback.runTestMethod(testResult);

               // Parameters can be contextual, so extract information
               swapWithClassNames(callback.getParameters());
               testResult.setParameters(callback.getParameters());
               if (testResult.getThrowable() != null) {
                   throw testResult.getThrowable();
               }
            }

            private void copyParameters(Object[] source, Object[] target)
            {
               for(int i = 0; i < source.length; i++)
               {
                  if(source[i] != null)
                  {
                     target[i] = source[i];
                  }
               }
            }

            private void swapWithClassNames(Object[] source)
            {
               // clear parameters. they can be contextual and might fail TestNG during the report writing.
               for(int i = 0; source != null && i < source.length; i++)
               {
                  Object parameter = source[i];
                  if(parameter != null)
                  {
                     source[i] = parameter.toString();
                  }
                  else
                  {
                     source[i] = "null";
                  }
               }
            }

            public Method getMethod()
            {
               return testResult.getMethod().getMethod();
            }

            public Object getInstance()
            {
               return Arquillian.this;
            }
         });
         if(result.getThrowable() != null)
         {
            testResult.setThrowable(result.getThrowable());
         }

         // calculate test end time. this is overwritten in the testng invoker..
         testResult.setEndMillis( (result.getStart() - result.getEnd()) + testResult.getStartMillis());
      }
      catch (Exception e)
      {
         testResult.setThrowable(e);
      }
View Full Code Here

        storeFirstFailure(testResult);
    }

    public void propagateThrowableAsTestResultAndRethrow(@Observes Throwable throwable) throws Throwable {
        if (responsePayload() != null) {
            storeFirstFailure(new TestResult(Status.FAILED, throwable));
        }

        // throwable must be rethrown, because Arquillian Core checks whether throwable was observed
        // and if yes, it does not let it bubble down the stack
        throw throwable;
View Full Code Here

    public TestResult getFirstNonSuccessfulResult() {
        for (ResponsePayload payload : payloads.values()) {

            if (payload != null) {

                TestResult testResult = payload.getTestResult();

                if (testResult != null) {
                    switch (testResult.getStatus()) {
                        case FAILED:
                            return testResult;
                        case SKIPPED:
                            return testResult;
                        case PASSED:
View Full Code Here

      if (testInstance != null)
      {
         try
         {
            TestResult result = null;
            try
            {
               try
               {
                  testInstance = ClassLoaderAdapterCallback.enhance(getClass().getClassLoader(),
                           testInstance.getClass().getClassLoader(), testInstance, testClass);
                  testInstance.getClass();
               }
               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

   @Inject @TestScoped
   private InstanceProducer<TestResult> testResult;
  
   public void execute(@Observes LocalExecutionEvent event) throws Exception
   {
      TestResult result = new TestResult();
      try
      {
         event.getExecutor().invoke(
               enrichArguments(
                     event.getExecutor().getMethod(),
                     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

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.