Skip to content

Warning when Is.Not.Null.Or.Empty usedΒ #189

Closed

Description

@Dreamescaper

Operators are a bit confusing in NUnit. Personally I don't fully understand how they work.

I've seen multiple times that constraint Is.Not.Null.Or.Empty is used to validate that string is not empty, which is wrong - it should be either Is.Not.Null.And.Not.Empty, or Is.Not.Null & Is.Not.Empty, or !Is.Null.Or.Empty.
But it might be missed because Not operator precedence is not obvious (one of the reasons I prefer using &/| operators instead of .And/.Or).

Since Is.Not.Null.Or.Empty constraint makes no sense (empty string or collection is always not null), I suggest always marking it as warning.

Any ideas for other commonly misused constraints?

Activity

  1. manfred-brands commented on Oct 31, 2025

    @manfred-brands
    Member

    After searching my work's code base and finding 60+ usages, I thought it is time for that rule.

  2. added this to the Release 4.12 milestone on Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions