Labs
In these labs we will write test cases in existing test classes. Our test cases will call other classes' methods and ensure that those methods throw exceptions.
- This lab uses
src/com.example.exceptionsjunit.reference.Calculatorandtest/com.example.exceptionsjunit.reference.CalculatorTests. Copy each class into yourcom.example.exceptionsjunit.labspackages - this package must exist in both thesrcandtestsource directories. (You will have to fix package declarations in the files after pasting.) - Integer division by zero is illegal and will throw
ArithmeticException. Add a test case for this toCalculatorTestsusingexpected. - Add the same test using try/catch.
(Solution: CalculatorTests.java)
-
The
src/com.example.exceptionsjunit.reference.StringReplacerclass has two methods. Each throws aBadInputException. -
Based on the code in
StringReplacer, add test cases totest/com.example.exceptionsjunit.reference.StringReplacerTeststhat verifies that these exceptions are thrown.
(Solution: StringReplacerTests.java)