docker - dotnet 测试未在 docker 中使用标志 --no-build 运行

标签 docker unit-testing .net-core nuget

我有一个单元测试(dotnet 应用程序),我在 docker 容器中运行下一个命令:“dotnet test mytest.csproj --no-build/p:CollectCoverage=true ...”。最终我没有得到测试的结果。当需要下载 nuget 包时,我使用一个标志 --no-build 来消除网络上的额外负载(它只发生在 docker 镜像中)。

在测试之前,我创建了一个 docker 镜像,我在其中构建了测试的项目。
然后当我在容器内运行测试时,我只得到一个状态:“构建成功”而不是运行测试。如果删除标志“--no-build”测试开始。或者,如果在运行测试之前执行“dotnet build”,即使使用标志 --no-build 也将运行测试。

我注意到如果在 .dll 文件“dotnet test mytest.dll --no-build/p:CollectCoverage=true ...”上测试运行成功,但这里有另一个问题:没有 cobertura 结果。并且参数/p:CollectCoverage=true 将无效。

我该如何解决这个问题?

屏幕上没有完整的 Dockerfile,只有 dotnet 所需的步骤

enter image description here

最佳答案

检查您的 sln 文件。
测试仅使用 --no-build 标志运行的情况可能是由于缺少 test.csproj 的发布或调试配置
例如,如果它只有调试配置,那么这将导致找不到测试:

dotnet build -c Release
dotnet test -c Release --no-build --list-tests
要诊断它,您可以提高详细程度。非常好,这还列出了已执行的测试用例及其状态:
dotnet test -c Release --no-build -v=normal

关于docker - dotnet 测试未在 docker 中使用标志 --no-build 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62416084/

相关文章:

mysql - 将 Wordpress 站点移动到 Docker : Error establishing DB connection

python - 错误 : pg_config executable not found when installing psycopg2 on Alpine in Docker

c# - System.Net.Http.HttpClient 如何选择认证类型?

azure - 在 Azure 容器实例 (ACI) 中运行 Gitlab Runner

python - 如何在目录中运行所有 Python 单元测试?

r - 使用 `testthat` 对写入/读取文件的函数或 Fortran 错误进行单元测试

python - 在 python 中将参数从 Suite 传递给 TestCase

.net - 在Dockerfile复制命令上找不到项目文件

c# - (502) 网关 PhantomJS 驱动程序初始化错误

java - 如何从 Java 项目运行 Docker 容器?