【问题标题】:Dotnet CLI build and test – just run the testsDotnet CLI 构建和测试——只需运行测试
【发布时间】:2018-05-17 21:09:11
【问题描述】:
**\*test*.dll

我想在 dotnet cli 上使用此架构,但找不到 dotnet 测试文档。我的项目文件结构是这样的 this

目前测试它查看 .sln 文件下的所有 .dll 文件。但我只想查看 tests.dll 文件

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

【问题讨论】:

    标签: visual-studio tfs command-line-interface xunit


    【解决方案1】:

    通过使用带有通配符的一些正则表达式的dotnet vstest,您无需任何脚本即可实现相同的目的。

    例如:

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

    第一个命令将生成带有 dll 的 Release 文件夹。第二个将运行所有找到匹配模式的测试 dll。

    这适用于 xUnit 框架。不确定其他框架。

    【讨论】:

      【解决方案2】:

      对于 dotnet 测试没有这样的过滤模式,对于 xUnit,我们只能通过 DisplayNameFullyQualifiedName 过滤测试,请参阅此链接以获取 dertails : 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
      

      【讨论】:

        【解决方案3】:

        在项目路径中输入 **/*Test.csproj,这样它只会运行测试测试项目。

        【讨论】:

          猜你喜欢
          • 2017-03-17
          • 1970-01-01
          • 1970-01-01
          • 2020-12-27
          • 2021-09-16
          • 1970-01-01
          • 2012-03-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多