[arquillian-issues] [JBoss JIRA] (ARQ-1963) Original exception lost when thrown from @Before-annotated method

Christian Schulz (JIRA) issues at jboss.org
Thu Jul 9 05:20:03 EDT 2015


     [ https://issues.jboss.org/browse/ARQ-1963?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christian Schulz updated ARQ-1963:
----------------------------------
    Steps to Reproduce: Throw an exception in the before method.  (was: {code}
@RunWith(Arquillian.class)
public class ExceptionTest {
    private Integer quantity;

    @Deployment
    public static Archive<?> createDeployment() {
        return ShrinkWrap.create(WebArchive.class);
    }

    @Before
    public void preparePersistenceTest() {
        quantity = null;
        throw new RuntimeException("test");
    }

    @Test
    public void adjustSuccessful() {
        assertTrue(quantity == null);
    }

    @After
    public void clearData() throws Exception {
        quantity.compareTo(1);
    }
}
{code})


> Original exception lost when thrown from @Before-annotated method
> -----------------------------------------------------------------
>
>                 Key: ARQ-1963
>                 URL: https://issues.jboss.org/browse/ARQ-1963
>             Project: Arquillian
>          Issue Type: Bug
>          Components: Base Implementation
>            Reporter: Christian Schulz
>
> 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.
> {code}
>     @Before
>     public void preparePersistenceTest() {
>         throw new RuntimeException("test");
> {code}
> A NPE occurs in @after-annotated method. The @test-annotated method doesn't fail fast.
> Here the console output:
> {code}
> 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)
> {code}
> *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



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the arquillian-issues mailing list