mardi 5 juin 2018

Should NullPointerExceptions be avoided in integration tests

While writing Integration tests for spring applications, I tend to come across checks for different Multilevel Objects For Eg:

AssertNotNull("Object D is null", getA().getB().getC().getD());

This assertions works well provided that Objects A -> B -> C are not null, otherwise if any one of these is null, you end up with an NPE. As it is not development code and I would like to see the cause of the failure and not a raw NPE, specially when I have 100 such tests that assert these. What would be the best practice in this case to avoid NPE or not avoid it at all?

Aucun commentaire:

Enregistrer un commentaire