Type to search pages and rules.

Browse pages

LS4001: Test Contains No Assertion

LS4001 is a compiler check that reports a test method that contains no assertion, because a test that asserts nothing passes whatever the code does and proves nothing about the scenario it names. This page states what the rule reports, where the error sits, and how to assert the result the test covers.

Markdown

Reference#

What the Rule Enforces#

LS4001 enforces Prove Each Scenario with a Test That Calls Its Use Case (litespec/backend/dotnet/testing#prove-each-scenario-with-a-test-that-calls-its-use-case). It runs in test projects only. Its category is LiteSpec.Tests. It reports an error and is enabled by default, as the Analyzers overview describes.

What the Rule Reports#

The rule reports a method carrying a test attribute (Fact, Theory, Test, TestCase, TestCaseSource, TestMethod, or DataTestMethod) whose body calls no assertion. An assertion is a call to a member of a type named Assert, or to a method whose name starts with Assert. The diagnostic sits on the method name.

Failing Example#

C#
public sealed class OrderTests
{
    [Fact]
    public void Place_WhenDraft_MarksPlaced()
    {
        var order = new Order();
        order.Place();
    }
}

Passing Example#

C#
public sealed class OrderTests
{
    [Fact]
    public void Place_WhenDraft_MarksPlaced()
    {
        var order = new Order();
        order.Place();
        Assert.True(order.Placed);
    }
}

How to Fix#

Assert the result the test covers: the state, event, call, response, or refusal the scenario names.

Notes#

What the Rule Ignores#

The rule does not report methods without a test attribute, even in a test project. It counts an assertion anywhere in the test body, including inside a local function. It does not run outside test projects.