java - How to test an exception scenario with Hamcrest -
i have method named execute() , returns boolean. under normal situations, returns true, if there exception, (say, dataaccessexception) capture exception , return false.
i trying figure out how test scenario in exception raised , "false" returned, using hamcrest.
so, here is:
public boolean execute() { try { ....... return true;} catch (dataaccessexception de) { ....... return false;} }
as suppressing dataaccessexception
inside execute
() method, not able test exception, rather can assert
result of method call shown below:
@test public void testexecute() { //mock code throw dataaccessexception mokito.dothrow(new dataaccessexception()).when(mockobj).methodname(somemethod); //now call execute method boolean actual = obj.execute(); assertthat(actual, false); }
Comments
Post a Comment