question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Workaround for ReSharper regarding `ShouldNotBeNull()`

See original GitHub issue

Please 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:open
  • Created 4 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

4reactions
dennisdoomencommented, Dec 13, 2021

That’s isn’t really helping either. But I’ve just reached out to Jetbrains to ask them if there is a better way.

4reactions
Evangelinkcommented, Jun 24, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found