Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-1963

Original exception lost when thrown from @Before-annotated method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • Base Implementation
    • None
    • Hide

      Throw an exception in the before method.

      Show
      Throw an exception in the before method.

      I have recognized that there seems to be an issue with JUnit and Arquillian.

      If there is an exception in @before-annotated method, it seems to be lost. There is no entry in the log neither the test will be aborted instantly.

          @Before
          public void preparePersistenceTest() {
              throw new RuntimeException("test");
      

      A NPE occurs in @after-annotated method. The @test-annotated method doesn't fail fast.

      Here the console output:

      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.979 sec <<< FAILURE! - in RelocateTest
      relocateSuccessful(RelocateTest)  Time elapsed: 0.24
      1 sec  <<< ERROR!
      java.lang.NullPointerException: null
              at RelocateTest.clearData(PackageRelocateTest.java:77)
      

      The issue
      testFailure in ExpectedExceptionHolder is notified and overwrite an existing exception https://github.com/arquillian/arquillian-core/blob/e39433696861f11588180894378c32f795da8085/junit/container/src/main/java/org/jboss/arquillian/junit/container/JUnitTestRunner.java#L110

      This exception is used to create the testresult:
      https://github.com/arquillian/arquillian-core/blob/e39433696861f11588180894378c32f795da8085/junit/container/src/main/java/org/jboss/arquillian/junit/container/JUnitTestRunner.java#L70

      In my opinion there are two ways to handle this issue:

      • Don't overwrite an existing exception and discard the new exception
      • Change the TestResult class to hold multiple exceptions

      The first approach could be implemented very fast. I can't imagine a case when other exceptions are really needed. I would say other exceptions occur because the first exception occurred.

      https://github.com/arquillian/arquillian-core/issues/86

            Unassigned Unassigned
            chschulz_jira Christian Schulz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: