As far as I know, we use the throw tests in cases where we need to make sure that something unexpected has happened.
I don't understand the logic of this piece of test code in junit testing
void testFindByIDThrows() {
given(specialtyRepository.findById(1L)).willThrow(new RuntimeException("boom"));
assertThrows(RuntimeException.class, () -> service.findById(1L));
then(specialtyRepository).should().findById(1L);
}
Why should I use willThrow testing when I can use other test methods like "willReturn" and also why the results of both methods are same?
Aucun commentaire:
Enregistrer un commentaire