Exceptions
DevMate can handle any exception or specific exception subclasses.
Github
You can find the code relating to this tutorial on Github in the /java/util/exceptions
folder.
Method under test
ExceptionDemo
doesn’t do a lot.

We have two methods.
generalException()
- will throw a generalException
ifdivisor = 0
.userException()
- will throw aDivideByZeroException
that we've defined underneath ifdivisor = 0
.
Configuring DevMate
We are only going to show the userException() method being tested. The process the generalException()
is very similar.
First, right-click the
userException()
method and choose Test with DevMate. Save the file. It will automatically open up the DevMate editor.

Set a representative for the valid equivalence class for the
number
parameter.Set a representative for the valid equivalence class for the
divisor
parameter.Set a representative for the invalid equivalence class for the
divisor
parameter.Set a representative for the valid equivalence class for the output.
Now we add our exception output. Click on the + icon and a valid equivalence class will be created.
Click the hamburger icon next to valid and select Toggle Valid/Invalid so it changes to a red invalid. This is actually cosmetic but it’s worth doing for clarity’s sake.
You’re now ready to add the invalid representative.
Click on the + button next to the newly toggled invalid equivalence class.

Click on the + icon
Search the know classes by entering a few letters to help us quickly find DivideByZeroException.
Click on it, once found and we’re done.
Generating Test Cases
Press Generate Test Cases. If there are test cases already present, you can delete them by pressing the Remove All Test Cases button in the top right.
You should now see the following screen. Complete the test cases definitions so you have what you see here.

Valid case - expects value of
5
for100 / 20
.Invalid output case - expects an exception
DivideByZeroException
ifdivisor == 0
.Press the Generate Test Code button.
Run the test
You can now open the test code file and run the test. It should pass.
Testing general/all exceptions
If you prefer, you can catch exceptions of any type by selecting Exception from the dropdown rather than a specific one.
Feel free to have a go!
Detectable exceptions
DevMate only works with exceptions that are explicitly stated in the method definition. Given
public static double userException(int number, int divisor) throws DivideByZeroException
it can pick up on DivideByZeroException
thanks to throws DivideByZeroException
. Without it, it would not appear in the dropdown list of available exceptions.