Last active
September 21, 2016 00:53
-
-
Save brunokim/9675101 to your computer and use it in GitHub Desktop.
Example of stacktrace hiding with ExpectedException rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'm not sure this is the minimal possible example, edits are welcome | |
package assertion; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.rules.ExpectedException; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
@RunWith(JUnit4.class) | |
public class ExpectedExceptionTest { | |
@Rule public final ExpectedException thrown = ExpectedException.none(); | |
@Test public void shouldFailWithStackTrace() { | |
try { | |
throw new NullPointerException(); | |
} finally { | |
Assert.assertNull(new Object()); | |
} | |
} | |
@Test public void shouldFailWithoutStackTrace() { | |
thrown.expect(IllegalArgumentException.class); // Expectation not satisfied | |
try { | |
throw new NullPointerException(); | |
} finally { | |
Assert.assertNull(new Object()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The stack trace still gets printed.