Why does this dotnet test test only work in a Docker container?

I have this .NET Core 1.1 solution, including an ASP.NET Core project and a NUnit test project. Each of the projects has the necessary properties (I can show more if necessary).

<PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
</PropertyGroup>

I can easily restore, build and run the test suite locally (Windows 10).

$ dotnet restore
Restoring packages for...
Restore completed in...
Generating MSBuild file...

$ dotnet build
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Example -> ...
  Test -> ...

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed ...

$ cd test/

$ dotnet test
Build started, please wait...
Build completed.

Test run for ...
Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in ...
NUnit3TestExecutor converted 11 of 11 NUnit test cases

Total tests: 11. Passed: 11. Failed: 0. Skipped: 0.
Test Run Succeeded.
Test execution time: ...

The test suite uses NUnit 3, and I'm in all the latest stable versions. Here are some interesting ref packages.

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
<PackageReference Include="FluentAssertions" Version="4.19.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.3" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />

However, when I run tests from the Docker.NET Core SDK image / container, they fail!

The active test run was interrupted. Reason: Unable to contact the test host process.

Here's a simple dockerfile

FROM microsoft/dotnet:1.1-sdk
WORKDIR /app
COPY . .

Search recovery and builds are found, but the test is interrupted!

$ docker image build --tag example:latest .
...
$ docker container run --rm -it example:latest
root@abcdef12345:/app# dotnet restore
...
root@abcdef12345:/app# dotnet build
...
root@abcdef12345:/app# cd test/
root@abcdef12345:/app# dotnet test
...
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in ...
NUnit3TestExecutor converted 11 of 11 NUnit test cases
The active test run was aborted. Reason: Unable to communicate with test host process.

. , . . , , !

+4

Source: https://habr.com/ru/post/1687336/


All Articles