Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

.net Unit Test Discovery through nuget package

$
0
0

We have many unit/integration tests in our solutions.Problem is each test can have its own version of these :

<ItemGroup><PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.27" /><PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /><PackageReference Include="xunit" Version="2.7.0" /><PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets></PackageReference><DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /></ItemGroup>

Parallely, we have a nuget package which contains test framework dependencies and shared code to help us writing tests.I'd like to add to this nuget package the dependencies you can see above.

Problem is, if I do this, that is removing these deps above and reference our test nuget package, unit tests are no more discovered.

For the moment, I've found a workaround using a Directory.Build.props file that is stored at the root level of our solution :

<?xml version="1.0" encoding="utf-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup><IsTestProject>false</IsTestProject></PropertyGroup>    <PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.UT')) or $(MSBuildProjectName.EndsWith('.IT'))"><IsTestProject>true</IsTestProject></PropertyGroup><PropertyGroup Condition="$(IsTestProject)"><IsPackable>false</IsPackable></PropertyGroup><ItemGroup Condition="$(IsTestProject)" ><PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.27" /><PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /><PackageReference Include="xunit" Version="2.7.0" /><PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"><PrivateAssets>all</PrivateAssets><IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets></PackageReference><DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /></ItemGroup>    </Project>

With this configuration, the unit tests no more need to have these deps because they share it.Notice how we conditionally add these deps using a simple naming convention :

  • *.UT for unit test projects
  • *.IT for integration test projects

So my question : is there a way to transfer this configuration in our test nuget package without breaking the discovery of the unit tests ?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>