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 Mark the Test That Proves Each Scenario (litespec/backend/testing#mark-the-test-that-proves-each-scenario). It runs in test projects only. Its category is LiteSpec.Tests. Severity and enablement follow the Analyzers overview.

What the Rule Reports#

The rule reports a method carrying a test attribute (Fact, Theory, Scenario, Test, TestCase, TestCaseSource, TestMethod, or DataTestMethod) that calls no assertion, neither in its own body nor in the body of a method it calls that the same project declares. An assertion is a call to a member of a type named Assert, or to a method whose name starts with Assert. A scenario method asserts through the step methods it runs, so a Then step that asserts satisfies the rule. 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 or a lambda, and one call deep into a method the project declares; it does not follow a call further. It does not run outside test projects.