Dotnet CLI build and test – just run the tests

余生长醉 提交于 2019-12-10 11:55:15

问题


**\*test*.dll

I want use this schema on dotnet cli but I can't found dotnet test documentation nothing.my project file structure is this way this.

At the moment tests It looking at all the .dll files under the .sln file. but I want just looking tests.dll files

dotnet test --no-build "**\*test*.dll" //?? All files in my project 

回答1:


There isn't such a pattern to filter that for dotnet test, we can only filter tests by DisplayName or FullyQualifiedName for xUnit, refer to this link for dertails : https://github.com/Microsoft/vstest-docs/blob/master/docs/filter.md

But it can only filter the tests, it cannot exclude other non-test project .dlls.

e.g.

dotnet test --filter "FullyQualifiedName=YourNamespace.TestClass1.Test1"

Howerever you can try writing PowerShell script to filter the test projects and run the command in the loop. Reference: Dotnet CLI – running tests from multiple assemblies

e.g.

Get-ChildItem | ? { $_.Name.Contains("Test") } | ForEach-Object { Push-Location; Set-Location $_.Name; dotnet test --no-build; Pop-Location}

Also this thread for your reference : https://github.com/Microsoft/vstest/issues/705


Another workaround is writing a cmd/bat script to run the test projects only:

e.g.

cd C:\TestProjectPath\A.Tests

dotnet test --no-build

cd C:\TestProjectPath\B.Tests

dotnet test --no-build

cd C:\TestProjectPath\C.Tests

dotnet test --no-build



回答2:


You achieve the same without any script by using dotnet vstest with some regular expression with wildcards.

For example:

dotnet build --configuration Release
dotnet vstest ./**/*Tests/bin/Release/**/*Tests.dll

the first command will generate the Release folder with the dll. The second will run all the test dll that finds matching the pattern.

This works well with xUnit frameworks. Not sure about other frameworks.




回答3:


In the Path to project(s) enter **/*Test.csproj so it will only run test Test project.



来源:https://stackoverflow.com/questions/47632734/dotnet-cli-build-and-test-just-run-the-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!