Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run .NET unit tests in a docker container

I have a .NET Core application containing MSTest unit tests. What would the command be to execute all tests using this Dockerfile?

FROM microsoft/dotnet:1.1-runtime
ARG source
COPY . .
ENTRYPOINT ["dotnet", "test", "Unittests.csproj"]

Folder structure is:

/Dockerfile
/Unittests.csproj
/tests/*.cs
like image 387
ddcc3432 Avatar asked May 30 '17 01:05

ddcc3432


1 Answers

Use a base image with .NET Core SDK installed. For example:

microsoft/dotnet
microsoft/dotnet:1.1.2-sdk

Then run a dotnet test console command. This is why SDK-based image is required - you cann't run dotnet test in a Runtime-based image without SDK. Here is a fully-workable Dockerfile example:

FROM microsoft/dotnet

WORKDIR /app
COPY . .

RUN dotnet restore

# run tests on docker build
RUN dotnet test

# run tests on docker run
ENTRYPOINT ["dotnet", "test"]

RUN commands are executed during a docker image build process.

ENTRYPOINT command is executed when a docker container starts.

like image 102
Ilya Chumakov Avatar answered Oct 12 '22 08:10

Ilya Chumakov