Using SonarLint for Visual Studio 4.11.1.0 - connected to a SonarQube Community Edition, Version 7.4 (build 18908) server,
using the NUnit Framework.
Receiving the following message, where in some cases it doesn’t make sense:
S2699:Tests should include assertions
This message is also shown if using [TestCase] attributes on a Test with an “ExpectedResult” set. If an “ExpectedResult” is set, then there is no additional Assertion needed, because this attribute itself is already the Assert.
Example:
[TestCase("Ä", 1, ExpectedResult = "Ä")]
[TestCase("Hallo", 100, ExpectedResult = "Hallo")]
[TestCase("Das ist ein Test", 4, ExpectedResult = "Das ")]
[TestCase("DasIsNTest", 5, ExpectedResult = "DasIs")]
public string TruncateTest(string value, int maxLength)
{
return value.Truncate(maxLength);
}
With returning the result in the test method and setting the ExpectedResult in the TestCase attributes the assertion is already done, but Sonar still shows the message, that there is an Assertion needed.