Dotnet CLI 构建和测试——仅 运行 个测试
Dotnet CLI build and test – just run the tests
**\*test*.dll
我想在 dotnet cli 上使用这个模式,但是我找不到 dotnet 测试文档 nothing.my 项目文件结构是这样的 this。
目前正在测试它查看.sln 文件下的所有.dll 文件。但我只想查看 tests.dll 个文件
dotnet test --no-build "**\*test*.dll" //?? All files in my project
没有这样的模式来过滤 dotnet 测试,我们只能通过 DisplayName 或 FullyQualifiedName 过滤 xUnit 的测试, 请参阅此 link 了解详情:https://github.com/Microsoft/vstest-docs/blob/master/docs/filter.md
但它只能过滤测试,不能排除其他非测试项目.dll。
例如
dotnet test --filter "FullyQualifiedName=YourNamespace.TestClass1.Test1"
但是您可以尝试编写 PowerShell 脚本来过滤测试项目和 运行 循环中的命令。参考:Dotnet CLI – running tests from multiple assemblies
例如
Get-ChildItem | ? { $_.Name.Contains("Test") } | ForEach-Object { Push-Location; Set-Location $_.Name; dotnet test --no-build; Pop-Location}
还有这个帖子供您参考:https://github.com/Microsoft/vstest/issues/705
另一种解决方法是将 cmd/bat 脚本仅写入 运行 测试项目:
例如
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
通过将 dotnet vstest
与一些带通配符的正则表达式结合使用,无需任何脚本即可实现同样的效果。
例如:
dotnet build --configuration Release
dotnet vstest ./**/*Tests/bin/Release/**/*Tests.dll
第一个命令将生成包含 dll 的 Release 文件夹。第二个将 运行 所有找到匹配模式的测试 dll。
这适用于 xUnit 框架。不确定其他框架。
在项目路径中输入 **/*Test.csproj 所以它只会 运行 测试测试项目。
**\*test*.dll
我想在 dotnet cli 上使用这个模式,但是我找不到 dotnet 测试文档 nothing.my 项目文件结构是这样的 this。
目前正在测试它查看.sln 文件下的所有.dll 文件。但我只想查看 tests.dll 个文件
dotnet test --no-build "**\*test*.dll" //?? All files in my project
没有这样的模式来过滤 dotnet 测试,我们只能通过 DisplayName 或 FullyQualifiedName 过滤 xUnit 的测试, 请参阅此 link 了解详情:https://github.com/Microsoft/vstest-docs/blob/master/docs/filter.md
但它只能过滤测试,不能排除其他非测试项目.dll。
例如
dotnet test --filter "FullyQualifiedName=YourNamespace.TestClass1.Test1"
但是您可以尝试编写 PowerShell 脚本来过滤测试项目和 运行 循环中的命令。参考:Dotnet CLI – running tests from multiple assemblies
例如
Get-ChildItem | ? { $_.Name.Contains("Test") } | ForEach-Object { Push-Location; Set-Location $_.Name; dotnet test --no-build; Pop-Location}
还有这个帖子供您参考:https://github.com/Microsoft/vstest/issues/705
另一种解决方法是将 cmd/bat 脚本仅写入 运行 测试项目:
例如
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
通过将 dotnet vstest
与一些带通配符的正则表达式结合使用,无需任何脚本即可实现同样的效果。
例如:
dotnet build --configuration Release
dotnet vstest ./**/*Tests/bin/Release/**/*Tests.dll
第一个命令将生成包含 dll 的 Release 文件夹。第二个将 运行 所有找到匹配模式的测试 dll。
这适用于 xUnit 框架。不确定其他框架。
在项目路径中输入 **/*Test.csproj 所以它只会 运行 测试测试项目。