Testing, Debugging, and Verification - Testing, Part II
Testing, Debugging, and Verification - Testing, Part II
Testing, Debugging, and Verification - Testing, Part II
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Testing</strong> for Exceptions<br />
JUnit can test for expected exceptions<br />
@Test (expected= IndexOutOfBoundsException . c l a s s )<br />
public void outOfBounds () {<br />
new ArrayList < Object >() . get (1) ;<br />
}<br />
expected declares that outOfBounds() should throw an<br />
IndexOutOfBoundsException.<br />
If it does<br />
◮ not throw any exception, or<br />
◮ throw a different exception<br />
the test fails.<br />
TDV: <strong>Testing</strong> /GU 121130 22 / 28