I have an Asp.net Core 6 Web Api project.
I am trying to protect against NullReferenceException
.
I have added the following setting to all projects:
<Nullable>enable</Nullable>
I have fixed the code base, but I get warnings in Unit and integration tests:
**viewModel**.Message.Should().Be("Aaaa");
viewModel
is underlined for a possible null
reference.
I think enabling this feature for unit tests is useless. When you write the unit test, you set up the conditions - so you know if something is null
.
Instead of putting the "!" (damnit) operator everywhere to tell the compiler I am sure it is not null, I believe I should just remove the <Nullable>enable</Nullable>
setting from test projects.
Does anyone see a valid reason <Nullable>enable</Nullable>
should stay in Unit test projects?