In a solution, I have 600 unit tests splitted in various libraries, and 450 of them are present in a single library. When running the tests on that specific library on my computer using Visual Studio (last version), everything goes well. But, on our build server, some tests never ends using the dotnet.exe test command.
dotnet.exe test C:\agent\_work\137\s\tests\XXX.Commercial.Infrastructure.Tests\XXX.Commercial.Infrastructure.Tests.csproj --logger trx --results-directory C:\agent\_work\_temp --configuration release -l "console;verbosity=detailed"
I tested the command on my local computer and everything goes well. I exectued the tests using Visual Studio on our build server directly and I could reproduce this issue on Visual Studio. I have to cancel the ones that never ends, and run them a second time to make them succeed.
Image of the Test Explorer on my local desktop
Image of the Test Explorer on the build server (test never end)
Image of Azure DevOps output after waiting 10 minutes after the last test and cancellation
The .csproj of the tests library where the issue occure
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<ProjectGuid>{7BFDD481-8C96-41BD-9B8E-B7E1ECE9A6AC}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture.AutoMoq" Version="4.11.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.11.0" />
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
On the internet, I found this but it's not related/doesn't solve my issue :
https://github.com/microsoft/vstest/issues/224
https://github.com/xunit/xunit/issues/1910
Edit
Here is a unit test that block for exemple :
[Fact]
public async Task SendSuccessReservationEmailConfirmationTest()
{
Reservation reservation;
using (var merchantContext = this._merchantContextFactory.Invoke())
using (var reservationContext = this._reservationContextFactory.Invoke())
{
var merchant = await merchantContext.Merchants.FirstOrDefaultAsync();
reservation = await reservationContext.Reservations
.FirstOrDefaultAsync(x => x.MerchantId.Equals(merchant.Id));
Assert.NotNull(reservation);
Assert.NotNull(merchant);
reservation.MerchantId = merchant.Id;
reservationContext.SaveChanges();
}
await this._reservationNotificationService.SendReservationConfirmationAsync(reservation.Id);
}
Edit 2
Visual Studio : 16.9.5
DotNet CLI : 5.0.203
Any idea? Thank you for your help