Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 22
    @BAmadeusJ, how would you tell if the nullPointerReference was coming from an assert in your test, or a bug in your SUT? Commented Feb 23, 2023 at 10:25
  • 3
    The stacktrace would tell me which line caused the issue and from there it's trivial to understand what hapenned. Commented Feb 23, 2023 at 10:35
  • 13
    @BAmadeusJ Which would require you to log, see, and interpret the stacktrace. Which may be anything but trivial. "You are getting the same information either way", as you stated, but how that information is presented can be just as important. Information is only information when you can parse (grok, grep, ...) it, otherwise it's just meaningless data. Commented Feb 23, 2023 at 13:15
  • 26
    @BAmadeusJ Also consider that while the information may be clear to you, some coworkers, especially more junior ones, might come across a nullPointerReference and assume that the test is corrupt. An explicit assertion removes any possible ambiguity. It does not require you to further interpret the given information. In short: It's more idiot-proof, which may or may not be important, depending on your opinion of your coworkers. :) Commented Feb 23, 2023 at 13:37
  • 9
    @Duroth TBH the OP sounds like the more junior member of the team, more experienced devs generally recognise the value of giving their future selves all the help they possibly can - such knowledge gained through painful experience! :-) Commented Feb 24, 2023 at 8:23