简体   繁体   中英

dotnet tests not run with flag --no-build in docker

I have a unit test (dotnet application), I run next command: "dotnet test mytest.csproj --no-build /p:CollectCoverage=true..." in a docker container. Eventually I do not get tests' results. I use a flag --no-build to remove extra load on network when need to download nuget packages(it happens only in docker image).

Before test I create a docker image where I do build test's project. Then when I run tests inside container I get only a status: "Build success" instead of running tests. If delete a flag "--no-build" tests start. Or if do "dotnet build" before run tests, test also will be run even with flag --no-build.

I've noticed that if test run on.dll file "dotnet test mytest.dll --no-build /p:CollectCoverage=true..." test run successfully, but here is another problem: no cobertura results. And an argument /p:CollectCoverage=true will be as invalid.

How can I fix this problem?

On the screen is not full Dockerfile, only with steps which necessary for dotnet

在此处输入图像描述

check your sln file. The case where tests are running only with --no-build flag can be caused by missing Release or Debug configuration for the test.csproj

if for example it has only Debug configuration, then this would result in no tests found:

dotnet build -c Release
dotnet test -c Release --no-build --list-tests

To diagnose it you could increase the verbosity level. What's pretty nice, this also lists the executed test cases and their status:

dotnet test -c Release --no-build -v=normal

Ran into the same problem. Adding the following property to the.csproj file of my test project resolved the issue:

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <PropertyGroup>
    ...
    <IsTestProject>true</IsTestProject>
    ...
  </PropertyGroup>
  ...
</Project>

For me, the problem was that I had not built the test code. I had only built my executable project. Now I first build the entire solution (and thus all projects including my test project).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM