This article will be useful for startups and early-stage projects that seek for free hosting for their apps.

THE MAIN BLOCK

So, let’s go to the point and return to the project structure from the previous article.

Image for post

The unit tests cover most of the code, and at the moment all tests are successful:

Image for post

To add the unit test validation to your continuous integration process, you’ll need to correct the dockerfile a bit:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["LimeHomeTest.Web/LimeHomeTest.Web.csproj", "LimeHomeTest.Web/"]
COPY ["LimeHomeTest.Services/LimeHomeTest.Services.csproj", "LimeHomeTest.Services/"]
COPY ["LimeHomeTest.Repository/LimeHomeTest.Repository.csproj", "LimeHomeTest.Repository/"]
COPY ["LimeHomeTest.Dto/LimeHomeTest.Dto.csproj", "LimeHomeTest.Dto/"]
COPY ["LimeHomeTest.Tests/LimeHomeTest.Tests.csproj", "Tests/LimeHomeTest.Tests/"]
RUN dotnet restore "LimeHomeTest.Web/LimeHomeTest.Web.csproj"
COPY . .
# testing
WORKDIR /src/LimeHomeTest.Web
RUN dotnet build
WORKDIR /src/LimeHomeTest.Tests
RUN dotnet test
WORKDIR "/src/LimeHomeTest.Web"
RUN dotnet build "LimeHomeTest.Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "LimeHomeTest.Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
CMD ASPNETCORE_URLS=http://*:$PORT dotnet LimeHomeTest.Web.dll

Compared to the previous version of dockerfile, here we can see that a copy of the project with tests was added to the image:

COPY ["LimeHomeTest.Tests/LimeHomeTest.Tests.csproj", "Tests/LimeHomeTest.Tests/"]

As well as running the tests to check their transmission:

WORKDIR /src/LimeHomeTest.Web
RUN dotnet build
WORKDIR /src/LimeHomeTest.Tests
RUN dotnet test

Let’s run a local image creation through the PowerShell to make sure the image is created successfully:

#unit-testing #startup #docker #heroku #github

Free .net core hosting on Heroku through Docker and GitHub. Deploy with Unit-tests
1.20 GEEK