Build/Test Issues

Xunit analyzer does not appear to affect NCrunch build

Started by kimbirkelund on 1,541 views

Xunit has a Roslyn analyzer that checks for various incorrect usages - such as an unused parameter in a theory. When enabling warnings-as-errors (by adding the TreatWarningsAsErrors property to the csproj) the warnings produced by this analyzer are turned into errors. However this does not affect the build performed by NCrunch. Other warnings (such as unused local variable) are correctly turned into errors when NCrunch builds the code.

The following csproj and test file exhibits this behavior with latest version of NCrunch:


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
    <PackageReference Include="xunit" Version="2.4.2" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>



using Xunit;

namespace TestProject1;

public class UnitTest1
{
	[Theory]
	[InlineData("value")]
	public void Test1(string value)
	{
	}
}
Hi, thanks for sharing this. I appreciate the sample code, this really helps a lot in troubleshooting these problems.

For performance reasons, NCrunch disables analyzers like this by default.

To turn them back on, enable the 'Allow code analysis' configuration setting for the projects involved.
I thought I'd tried that, but must have applied the setting to the wrong project. Thanks for the help.
This post has been deleted.
This post has been deleted.
This post has been deleted.
This post has been deleted.
This post has been deleted.
This post has been deleted.

Post a reply

Log in to reply.