Home > Mobile >  dotnet tests fails in container as a part of docker build, but works when run manually
dotnet tests fails in container as a part of docker build, but works when run manually

Time:04-20

I'm trying to run dotnet tests from my Dockerfile but when i do it fails with the following error:

=> [7/9] RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true                                                                                                                     28.2s 
 => [8/9] RUN cd /builds/tests                                                                                                                                                                    0.5s 
 => ERROR [9/9] RUN dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\TestResults\test-results.xml;MethodFormat=Class;FailureBodyFormat=Verbose"                                   0.5s 
------
 > [9/9] RUN dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\TestResults\test-results.xml;MethodFormat=Class;FailureBodyFormat=Verbose":
#13 0.508 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
------
executor failed running [/bin/sh -c dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\TestResults\test-results.xml;MethodFormat=Class;FailureBodyFormat=Verbose"]: exit code: 1

But there is a test project (csproj) file in the /builds/tests folder. Here's the output from that folder from a running container:

root@00b0dd66f0a7:/builds/tests# ls -lah
total 80K
drwxr-xr-x 1 root root 4.0K Apr 18 19:20 .
drwxr-xr-x 1 root root 4.0K Apr 19 18:20 ..
-rwxr-xr-x 1 root root  690 Mar 30 18:01 AzureServiceBusQueueTestClient.cs
-rwxr-xr-x 1 root root  429 Mar 30 18:01 AzureStorageQueueTestClient.cs
-rwxr-xr-x 1 root root 1.6K Mar 30 18:01 AzureStorageTableEnqueuedTestClient.cs
-rwxr-xr-x 1 root root  887 Mar 30 18:01 ListLogger.cs
-rwxr-xr-x 1 root root  116 Mar 30 18:01 LoggerTypes.cs
-rwxr-xr-x 1 root root  259 Mar 30 18:01 NullScope.cs
-rwxr-xr-x 1 root root 2.6K Apr 18 19:11 widgetStorageRequestsShould.cs
-rwxr-xr-x 1 root root   88 Mar 30 18:01 README.md
-rwxr-xr-x 1 root root 6.0K Apr 18 18:05 TestFactory.cs
-rwxr-xr-x 1 root root 2.1K Apr 18 19:11 widgetRequestsShould.cs
drwxr-xr-x 1 root root 4.0K Apr 18 19:20 bin
drwxr-xr-x 1 root root 4.0K Apr 19 18:20 obj
-rwxr-xr-x 1 root root 1.2K Mar 30 18:01 widgets-tests.csproj

However, if I run it manually after the container is built it works fine:

# cd /builds/tests/
# bash
root@00b0dd66f0a7:/builds/tests# dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\TestResults\test-results.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
  Determining projects to restore...
  Restored /builds/src/widgets.csproj (in 17.16 sec).
  Restored /builds/tests/widgets-tests.csproj (in 17.85 sec).

 ....
Test run for /builds/tests/bin/Debug/net6.0/widgets-tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
widgets File: /builds/TestResults/test-results.xml

Passed!  - Failed:     0, Passed:     3, Skipped:     0, Total:     3, Duration: 23 ms - /builds/tests/bin/Debug/net6.0/widgets-tests.dll (net6.0)
root@00b0dd66f0a7:/builds/tests#

Dockerfile

This is what my current Dockerfile looks like:

FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:6.0
RUN apt update && apt-get install vim -y
COPY . /builds
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
RUN apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install nodejs
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm true
RUN cd /builds/tests
# RUN dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\TestResults\test-results.xml;MethodFormat=Class;FailureBodyFormat=Verbose"

I'm sure I'm just missing something simple but I can't seem to find it. Any tips would be appreciated.

CodePudding user response:

RUN cd /builds/tests \
    && dotnet test ..

or

WORKDIR /builds/tests instead of RUN cd /builds/tests

  • Related