#16543
3 years ago
16 Mar 2023 09:30 UTC
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)
{
}
}
#16544
3 years ago
16 Mar 2023 22:48 UTC
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.
#16545
3 years ago
17 Mar 2023 07:48 UTC
I thought I'd tried that, but must have applied the setting to the wrong project. Thanks for the help.
Deleted post
#16567
3 years ago
30 Mar 2023 11:18 UTC
This post has been deleted.
Deleted post
#16578
3 years ago
04 Apr 2023 11:10 UTC
This post has been deleted.
Deleted post
#16616
3 years ago
19 Apr 2023 04:13 UTC
This post has been deleted.
Deleted post
#16622
3 years ago
25 Apr 2023 05:30 UTC
This post has been deleted.
Deleted post
#16632
3 years ago
26 Apr 2023 09:18 UTC
This post has been deleted.
Deleted post
#16636
3 years ago
27 Apr 2023 04:25 UTC
This post has been deleted.