【问题标题】:xUnit tests not found when running in docker container在 docker 容器中运行时未找到 xUnit 测试
【发布时间】:2019-03-05 23:02:42
【问题描述】:

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

/ciad/tests/bin/Debug/netcoreapp2.1/Tests.dll 中没有可用的测试。确保测试发现者和执行者已注册并且平台和框架版本设置正确,然后重试。

这里是 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 .

【问题讨论】:

  • 错误涉及/ciad/tests/。测试源在哪里?它们在/ciad/tests//ciad/Tests/ 下吗?那是 t 还是 T。 Linux 上的大小写很重要。
  • 项目名称为Tests.csproj。由于“RUN dotnet restore tests/Tests.csproj”行有效,那么我确定问题不在于大写 T。
  • 基本上我想知道是否有人对错误消息中的“测试发现者和执行者已注册”部分有任何想法?
  • RUN dotnet restore tests/Tests.csproj 之所以有效,是因为您将 csproj 复制到了 tests/,而不是 Tests。而restore 只使用项目文件,不使用代码。该代码从未存在于tests/,也从未编译过,也无法被dotnet test 找到/执行。
  • 感谢您的评论,但是如果您检查我对问题的回答,为什么当我将所有内容更改为小 t 时它会起作用?这是相同的方法,不是吗?

标签: docker .net-core containers xunit


【解决方案1】:

我不知道出了什么问题,但最终感谢 omajid 的提示,我将测试项目的名称和文件夹更改为使用小 t 的测试,并将 Dockerfile 中的所有其他大写 T 更改为小 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

【讨论】:

    猜你喜欢
    • 2020-04-22
    • 2022-12-11
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2018-09-21
    • 1970-01-01
    相关资源
    最近更新 更多