Reputation: 4513
I have created a project with just one method and I have written a unit test on it and the unit test passed locally. But not sure why after running sonar cloud scanner, it shows zero percent coverage.
This is the test class
public class DataStructureTest
{
private readonly DataStructure ds;
public DataStructureTest()
{
ds = new DataStructure();
}
[Theory, MemberData(nameof(LongestString_Return_Longest_String_ShouldPass_Data))]
public void LongestString_Return_Longest_String_ShouldPass(string input, string expect)
{
// Act
var actual = ds.LongestString(input);
// Assert
Assert.Equal(expect, actual);
}
public static TheoryData<string, string> LongestString_Return_Longest_String_ShouldPass_Data()
{
return new TheoryData<string, string>
{
{ "Hello John", "Hello" },
{ "Hi John and Mandy", "Mandy" }
};
}
}
Upvotes: 0
Views: 2701
Reputation:
You have to be careful about what these softwares mean when they use some term. For example, SonarQube has following article: https://community.sonarsource.com/t/sonarqube-and-code-coverage/4725
FAQ has this as first question:
Q: After migrating from 5.6 to 6.7 my coverage shows 0%, why is that ? R: Since SonarQube 6.2 and the implementation of the MMF-345 565, if no coverage information is found the coverage is then set to zero by default.
I think your case may come under this.
Upvotes: 1