Your project contains only TEST-code for language cs; scanning SpecFlow project

  • ALM used (Azure DevOps)
  • CI system used (Azure DevOps)
  • Scanner command used when applicable (private details masked)
extraProperties: |
  sonar.scanner.scanAll=false
  sonar.inclusions=**/*.cs
  sonar.exclusions=**/*.json
  sonar.test.inclusions= 
  sonar.test.exclusions= 
  sonar.dotnet.excludeTestProjects=false
  • Languages of the repository (cs)
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
Last analysis has warnings
Analysis ID "AZMyOcZ12mM7fGQ6k0tM"
Your project contains only TEST-code for language C# and no MAIN-code for any language, so only TEST-code related results are imported. 
  • Steps to reproduce
    We have a separate test project that contains specflow (and xunit) BDD style tests, ideally we would like to use sonar cloud to scan the cSharp code written for the step definitions, but we have been able to configure sonar to treat the test project as code to scan.

We are using a Azure yaml pipeline and have tried several different configurations, including properties such as;

sonar.inclusions=**/*.cs
sonar.dotnet.excludeTestProjects=false

But every time the sonar analysis reports that the project only contains test code. Any ideas; is there anything in the above analysis that could help? AZMyOcZ12mM7fGQ6k0tM

I’ve also reviewed the documentation provided, but could not find anything that would point to the cause.

Thanks in advance for any help or suggestions you might have.

Hi there, @PaulD

I am not sure I understand your configuration.
Could you detail the architecture of your repo in terms of projects, and what type of code you would expect SonarQube Cloud to find in it?

Denis

Certainly, more specifically, we have a donet core solution that contains an implementation of a SpecFlow test project.

While we might typically exclude test projects, in this case, we want to ensure that the implementation of the Steps within the BDD / Gerkin feature files meets our quality guidelines, etc.

The solution structure is approximate;

(I’ve created some example step definitions to demonstrate the cs code we want to be scanned).
Within these steps you will find test code, (using xunit) to asset for the THEN phase of the Given When Then, gherkin syntax.

OK, as I suspected your solution only contains test code, which is what the scanner is telling you.

If you want, you can tweak the analysis by asking it to consider this as MAIN code (which will also enable many more rules, as we do not enable them on TEST code).

As indicated in the documentation, you can include the following in your csproj:

<PropertyGroup>
  <SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

This should change the way we consider your code, and remove that warning.

Denis

1 Like

Thanks Denis, let me give that a try, I was hoping it could be managed via sonar properties, watch this space, I’ll test and report back; thanks again.

Update - That seems to have done the trick, despite the other settings, it was the project group that was required. Thanks again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.