Tests should include assertions, false positive for C# JustMock Assert() helper

I have code similar to this:

//Arrange
var mock = Mock.Create<IFoo>().Arrange(x=>x.DoFoo()).OccursOnce();
// Act
mock.DoFoo();
// Assert
mock.Assert();

And this method triggers the rule “Test should include assertions”.
This pattern occurs frequently in my code.
I can add the suggested attribute to the assertion code because I don’t own that code, it’s part of the JustMock library.

How do I fix this either in my configuration, code or otherwise?

Hey there.

What version of SonarQube are you using?

  • Developer Edition
  • Version 9.9.2 (build 77730)

Hello @anemitoff,

Welcome to the community!

I am not able to reproduce the issue with your code snippet, here is what I have:

using NUnit.Framework;
using Telerik.JustMock;
using Telerik.JustMock.Helpers;

[TestFixture]
public class FooTests
{
    public interface IFoo
    {
        void DoFoo();
    }

    [Test]
    public void Test1()
    {
        //Arrange
        var mock = Mock.Create<IFoo>();
        mock.Arrange(x => x.DoFoo()).OccursOnce();

        // Act
        mock.DoFoo();

        // Assert
        mock.Assert();
    }
}

The issue does not raise in my case and if I remove the mock.Assert then the issue raises as expected.

  • Could you tell me which test framework you are using? (NUnit, MSTest, xUnit…)
    • Which version?
  • Which version of JustMock are you using?

Thank you,