Workaround for ReSharper regarding `ShouldNotBeNull()`
See original GitHub issuePlease take a look at this code:
var car = new Car();
Assert.IsNotNull(car);
Assert.IsTrue(car.HasEngine);
When using ReSharper, it works perfectly fine without any complaints. Now I “translate” the code into…
var car = new Car();
car.ShouldNotBeNull();
car.HasEngine.Should().BeTrue();
… which makes ReSharper complaining about the last line saying that car
can be null.
There is a ReSharper issue regarding this topic as well: Extend support for FluentAssert
Do you see any lightweight workaround that can be included in FluentAssertions without polluting the code base with a dependency to a third-party tool?
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (15 by maintainers)
Top Results From Across the Web
Null Checking | ReSharper Documentation
This will let ReSharper notify you when null objects are passed to the decorated parameters. You can disable adding [NotNull] by clearing the ......
Read more >When testing an instance for null with Should().NotBeNull ...
Fluentassertions: When testing an instance for null with Should().NotBeNull(), ReSharper still indicates, that there is a possible null reference exception.
Read more >Extend support for FluentAssert : RSRP-442740 - YouTrack
RSRP-329387 Fluentassertions: When testing an instance for null with Should().NotBeNull(), ReSharper still indicates, that there is a possible null ...
Read more >Configure code inspection settings - ReSharper
Select ReSharper | Options from the main menu or press Alt+R O , then choose Code Inspection | Settings on the left.
Read more >Value and nullability analysis | ReSharper Documentation
In this mode, ReSharper warns about possible 'null' dereference in all contexts where the value is not checked for nullability explicitly, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s isn’t really helping either. But I’ve just reached out to Jetbrains to ask them if there is a better way.
I don’t think null pointer warnings in unit tests are such a big deal because it is still caught before any prod.
At the same time, and I might be wrong with it, but I would favor having some False Negatives instead of False Positives here. Most people are probably using the simple scenario and would prefer not to have a FP message from ReSharper. For more advanced users, who will wrap assertions in the
AssertionScope
they would end up with a False Negative (no message from ReSharper).just my 2 cents