gpt4 book ai didi

docker - 在 docker 容器中运行时找不到 xUnit 测试

转载 作者:行者123 更新时间:2023-12-02 18:28:32 27 4
gpt4 key购买 nike

我正在为带有一些 xUnit 测试的 dotnet 核心项目制作 Dockerfile。我想在构建图像时运行单元测试。但是,当我进行 docker 构建时,我在测试步骤中收到以下消息:

No test is available in /ciad/tests/bin/Debug/netcoreapp2.1/Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

这是 Dockerfile:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
FROM microsoft/dotnet:2.1-sdk AS build

WORKDIR /ciad

# restore
COPY API/API.csproj ./api/
RUN dotnet restore api/API.csproj
COPY Tests/Tests.csproj ./tests/
RUN dotnet restore tests/Tests.csproj

# copy src
COPY . .

# test
RUN dotnet test tests/Tests.csproj

我知道这是一个不完整的 dockerfile。我现在只是坚持测试。谁能看到我错过了什么?

值得一提的是,测试在 VS 中运行良好,“dotnet test”命令也能正常工作。我还可以看到测试项目的文件已复制到容器中。我跑:

docker build -t testing .

最佳答案

我不知道出了什么问题,但最终感谢 omajid 的提示,我将测试项目的名称和文件夹更改为 tests with small t 并将 Dockerfile 中的所有其他大写字母 T 更改为 small t 并且成功了!我希望这可以帮助某人。

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
FROM microsoft/dotnet:2.1-sdk AS build

WORKDIR /ciad

# restore
COPY API/API.csproj ./api/
RUN dotnet restore api/API.csproj
COPY tests/tests.csproj ./tests/
RUN dotnet restore tests/tests.csproj

# copy src
COPY . .

# test
RUN dotnet test tests/Tests.csproj

关于docker - 在 docker 容器中运行时找不到 xUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55013000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com