nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

Check if test does not have assert(s).

Open JohanLarsson opened this issue 5 years ago • 5 comments

For catching mistakes like:

[Test]
public void SomeTest()
{
    // Assert.AreEqual(...);
}

Perhaps very common.

Don't warn if [Ignore] or [Explicit]

JohanLarsson avatar Feb 17 '19 07:02 JohanLarsson

Not sure is possible. Asserts might be present somewhere in user code, not nessesary directly in test method. Besides, external assertion libs (e.g. FluentAssertions) would be a pain as well, I suppose

Dreamescaper avatar Feb 18 '19 00:02 Dreamescaper

I use Shouldly a lot these days, so this would be every test method for me. Maybe an opt-in diagnostic would make sense?

jnm2 avatar Feb 27 '19 22:02 jnm2

The usefulness is perhaps negative, not a common bug. We had a guy who had a habit of commenting out the body of test methods or asserts that were troublesome. 🙂

JohanLarsson avatar Feb 28 '19 10:02 JohanLarsson

Empty test method bodies sound like a good thing to warn for. What do you think?

jnm2 avatar Feb 28 '19 12:02 jnm2

Yes it is a trivial analyzer with nonzero value.

JohanLarsson avatar Mar 01 '19 07:03 JohanLarsson