I created NUnit project through Visual Studio and trying to run it in Docker.
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["TestProject1.csproj", "TestProject1/"]
RUN dotnet restore "TestProject1/TestProject1.csproj"
COPY . .
WORKDIR "/src/TestProject1"
RUN dotnet build "TestProject1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "TestProject1.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base as final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "test", "TestProject1.dll", "/TestAdapterPath:."]
I built an image with docker build -t tests . And finally, I ran it, but it did not execute tests. Without the last parameter it also says Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:<pathToCustomAdapters>.. I am not sure which parameter I should include to run dotnet test or am I using the wrong sdk image?
PM> docker run tests
Microsoft (R) Test Execution Command Line Tool Version 17.7.1 (x64) Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait... A total of 1 test files matched the specified pattern. No test is available in /app/TestProject1.dll. Make sure that test discoverer & executors > are registered and platform & framework version settings are appropriate and try again.
namespace TestProject1
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
Assert.Pass();
}
}
}
The Docker file was autogenerated by VS and I had to trim the file to make it work -
dotnet testbuilds and restores the project, so build and publish steps were unnecessary. But I still don't know what's wrong with the Docker in my question.