Let's consider the following test.
[Fact]
public void MyTest()
{
// Arrange Code
var sut = new SystemWeTest();
// Act Code
var response = sut.Request();
// Assert
response.Should().NotBeNull();
response.ResponseCode.Should().Be("1");
response.Errors.Should().BeEmpty();
}
I have argued with a few colleagues that it's pointless to assert that 'response' is not null if you are going to then assert on some of its internals. Of course, if the only thing that you are interested is checking that the object is not null, nothing more, then it's fine.
My thinking is that each following assert statements are in fact implicit assertions that 'response' is not null. If it is null then it would throw a null reference exception and making the test fail as expected.
The only benefit I see from doing this is a somewhat clearer message on why the test failed. You'd get your test framework specific exception that's thrown by the 'NotBeBull' assertion instead of the generic 'nullReferenceException'. I don't feel this is useful as you are getting the same information anyway.
Am I missing something here? Does checking for null have any benefits in the example provided?