如何在Docker容器中运行.NET单元测试 [英] How to run .NET unit tests in a docker container

查看:103
本文介绍了如何在Docker容器中运行.NET单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含MSTest单元测试的.NET Core应用程序。使用此Dockerfile执行所有测试的命令是什么?

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"]

文件夹结构为:

/Dockerfile
/Unittests.csproj
/tests/*.cs


推荐答案

使用安装了.NET Core SDK的基本映像。例如:

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

microsoft/dotnet
microsoft/dotnet:1.1.2-sdk

然后运行 dotnet测试控制台命令。这就是为什么需要基于SDK的映像的原因-如果没有SDK,您将无法在基于运行时的映像中运行 dotnet测试。这是一个完全可行的 Dockerfile 示例:

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 命令在docker映像构建过程中执行。

RUN commands are executed during a docker image build process.

ENTRYPOINT 命令在Docker容器启动时执行。

ENTRYPOINT command is executed when a docker container starts.

这篇关于如何在Docker容器中运行.NET单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆