JUnit continue to assert things after expected exception

exception, java, junit

Solution

You could use a `finally`:

@Test(expected = IllegalArgumentException.class)
public void cdIntoNonExistantFolder() {
    try {
        cdTool.changeDirectory("nonexistant");
    }
    finally {
        assertThat(cdTool.getStatusCode(), not(equalTo(0)));
    }
}

Problem

I have something like ``` @Test(expected = IllegalArgumentException.class) public void cdIntoNonExistantFolder() { cdTool.changeDirectory("nonexistant"); assertThat(cdTool.getStatusCode(), not(equalTo(0))); } ``` I believe the `assertThat` does not run as `changeDirectory` will throw the exception. Is it possible to make it still run?

Original source