vendredi 1 avril 2016

Verify that an Exception was thrown in jUnit

I've a method that looks like this:

public void doSomething(String argument1) {
  try {
    // Parse a list of arguments & if certain keys are not present,
    // throw an exception. 
    try {
      //Fetch data from data store & process in a loop
    }
    catch(ApplicationException ae) {
      // Log & proceed.
    }
  }
  catch (InternalException ie) {
    //Print some error message. No exception propagation.
  }
}

The InternalException is thrown when some key arguments are missing in the argument passed to the method. I need to test the method to ensure that InternalException was thrown.

jUnit's expected & Rule do not help in this regard.

How do I go about testing this scenario?

Aucun commentaire:

Enregistrer un commentaire