04.12.2012 Views

Testing, Debugging, and Verification - Testing, Part II

Testing, Debugging, and Verification - Testing, Part II

Testing, Debugging, and Verification - Testing, Part II

SHOW MORE
SHOW LESS

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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!