Как запустить .net модульных тестов в Докер без установки всего SDK? [закрыто]


April 2019


29 раз


Есть ли способ запустить .net модульных тестов (XUnit или другие) в Докер без установки всего SDK?

Я хотел бы иметь минимальную Docker изображение, которое будет использоваться исключительно для запуска моих тестов.

1 ответы


No. Running tests requires the SDK. However, it is possible to use layers to remove this dependency from the final image. For example, if your ultimate goal was to have just the running app, but you wanted to build and test inside the container first before running it, then you could do:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
# do your build, test, publish

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
# copy published files from build-env

In the end, your image would just reference the ASP.NET Core runtime, not the SDK. It should be noted, though, that this will run your tests when creating the image in the first place, not each time the container runs. That should actually be sufficient, though, since if the tests passed during the build, the published app in the final image will work as well. There's really no need to test it over and over. However, if you're wanting an image devoted entirely to testing, then you'll need to build off the SDK image.

Связанные вопросы