Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Xunit analyzer does not appear to affect NCrunch build
kimbirkelund
#1 Posted : Thursday, March 16, 2023 9:30:37 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 7
Location: Denmark

Thanks: 1 times
Was thanked: 4 time(s) in 3 post(s)
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:

Code:

<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>


Code:

using Xunit;

namespace TestProject1;

public class UnitTest1
{
	[Theory]
	[InlineData("value")]
	public void Test1(string value)
	{
	}
}
Remco
#2 Posted : Thursday, March 16, 2023 10:48:59 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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.
1 user thanked Remco for this useful post.
kimbirkelund on 3/17/2023(UTC)
kimbirkelund
#3 Posted : Friday, March 17, 2023 7:48:48 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/9/2019(UTC)
Posts: 7
Location: Denmark

Thanks: 1 times
Was thanked: 4 time(s) in 3 post(s)
I thought I'd tried that, but must have applied the setting to the wrong project. Thanks for the help.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.026 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download