-
Notifications
You must be signed in to change notification settings - Fork 763
Closed
Description
When using NUnit tests with MTP mode the execution of tests is not terminated when CTRL+C key is pressed in the console. It is visible that CtrlCIssue.UnitTests.Test event is raised, but test engine is running forever from that point. If no CTRL+C is pressed, test session ends in 5 seconds as there is only one test with 5s sleep code.
I tried the same case with MSTest tests, to identify if the issue is in MTP code or NUnit (adapter). When MSTest used instead of NUnit, behavior is correct. After CTRL+C the test session is finished and properly reported. When NUnit is used, I have to kill the process externally (via Task Manager or PowerShell).
How to simulate:
- Compile the example below
- Execute
CtrlCIssue.exe --no-ansi --output Detailedcommand (using no-ANSI console reporter for better logging in the example, MTP logger has no impact) - Right after execution when
NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit runmessage is displayed, hit the CTRL+C key. - After few second warning exception is displayed
The operation was canceled., but execution never stops. The messageCanceling the test session...comes from MTP whenConsole.CancelKeyPressevent is raised.
Screenshot from the execution
CtrlCIssueMSTest.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnableNUnitRunner>true</EnableNUnitRunner>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Microsoft.Testing.Extensions.Telemetry" Version="2.0.2" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="2.0.2" />
<PackageReference Include="Microsoft.Testing.Extensions.VSTestBridge" Version="2.0.2" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.0.2" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="2.0.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.8.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
</ItemGroup>
</Project>
UnitTests.cs
using NUnit.Framework;
using System.Threading;
namespace CtrlCIssue
{
[TestFixture]
public class UnitTests
{
[Test]
public void Test()
{
Thread.Sleep(5000);
}
}
}
Reactions are currently unavailable