xUNIT softwaretest with .NET CORE and Docker

  .net-core, c#, docker, xunit

I have a solution which contains two projects which has the following structure:

enter image description here

The project "TestWebApp" is a xUnit testproject and contains the software tests. The project "WebApplication" the software which should be tested with the testproject.

The software works fine but by now i would like to build a docker container which should be included in a gitlab ci-cd pipeline. My question contains two steps:

  1. Should i build a container which contains the business application ("WebApplication") and the software test ("TestWebApp")? If this is the case how could i do that? How can i run the software test in the container? My Dockerfile looks like the following
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base

FROM microsoft/dotnet:2.2-sdk AS build
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
COPY ["TestWebApp/TestWebApp.csproj", "TestWebApp/"]

#WORKDIR "WebApplication1"
#RUN dotnet restore WebApplication1.csproj
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app

FROM base AS final
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
  1. If i shouldn’t build a container with business application and test – what would be the correct way?

Source: Docker Questions