【问题标题】:Running unit tests in TFS/VSO Build vNext using xUnit adapter使用 xUnit 适配器在 TFS/VSO Build vNext 中运行单元测试
【发布时间】:2015-08-07 06:10:00
【问题描述】:

我正在尝试使用 Visual Studio Online 的 Build vNext 平台中的 xUnit 测试适配器运行我们的 xUnit 测试。

按照this article的规定,我们需要提供一个自定义的测试适配器路径指向xunit.runner.visualstudio.testadapter.dll

但是这个包被NuGet还原到一个全局包文件夹,即C:\Users\{user}\.dnx\packages?

如何在构建步骤中引用此文件夹?

我们正在使用 VS 2015 和 DNX 项目。

编辑:

我什至尝试过直接指向包路径DLL:

C:\Users\buildagent\.dnx\packages\xunit.runner.visualstudio\2.1.0-beta4-build1109\build\_common

它似乎仍然没有使用适配器:

Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\a\8ac4a4f6\Root\artifacts\bin\MyProject.UnitTest\release\dnx451\TransitApi.UnitTest.dll"  /TestAdapterPath:C:\Users\buildguest\.dnx\packages\xunit.runner.visualstudio\2.1.0-beta4-build1109\build\_common /UseVsixExtensions:true /logger:trx
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
Copyright (c) Microsoft Corporation.  All rights reserved.
Starting test execution, please wait...
Warning: No test is available in C:\a\8ac4a4f6\Root\artifacts\bin\MyProject.UnitTest\release\dnx451\TransitApi.UnitTest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
No results found to publish.

project.json,如果相关:

"dependencies": {
  "xunit": "2.1.0-beta4-build3109",
  "xunit.runner.dnx": "2.1.0-beta4-build134",
  "xunit.runner.visualstudio": "2.1.0-beta4-build1109"
},

"commands": {
  "test": "xunit.runner.dnx"
},

"frameworks": {
  "dnx451": { }
}

【问题讨论】:

    标签: visual-studio-2015 azure-devops dnx xunit.net azure-pipelines


    【解决方案1】:

    创建一个global.json 文件并将以下内容放入其中:

    {
      "packages": "packages"
    }
    

    这将迫使您的dnu restore 将包放入.\packages\,这有望解决问题。只需将测试适配器路径指定为 $(Build.SourcesDirectory)\packages\ ——您可能必须指定完整的程序集名称,我不确定我的想法。


    更新:我采用了示例“HelloMvc”应用程序,并使用 xUnit 测试构建它,而没有 global.json。这是我的构建定义:

    {
      "build": [
        {
          "enabled": true,
          "continueOnError": false,
          "alwaysRun": false,
          "displayName": "Restore packages",
          "task": {
            "id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
            "versionSpec": "*"
          },
          "inputs": {
            "filename": "$(DNXPath)\\dnu.cmd",
            "arguments": "restore",
            "workingFolder": "",
            "failOnStandardError": "false"
          }
        },
        {
          "enabled": true,
          "continueOnError": false,
          "alwaysRun": false,
          "displayName": "Run tests",
          "task": {
            "id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
            "versionSpec": "*"
          },
          "inputs": {
            "filename": "$(DNXPath)\\dnx.exe",
            "arguments": "test",
            "workingFolder": "",
            "failOnStandardError": "false"
          }
        },
        {
          "enabled": true,
          "continueOnError": false,
          "alwaysRun": false,
          "displayName": "Build NuGet package",
          "task": {
            "id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
            "versionSpec": "*"
          },
          "inputs": {
            "filename": "$(DNXPath)\\dnu.cmd",
            "arguments": "publish",
            "workingFolder": "",
            "failOnStandardError": "false"
          }
        },
        {
          "enabled": true,
          "continueOnError": false,
          "alwaysRun": false,
          "displayName": "Publish Artifact: drop",
          "task": {
            "id": "1d341bb0-2106-458c-8422-d00bcea6512a",
            "versionSpec": "*"
          },
          "inputs": {
            "CopyRoot": "",
            "Contents": "**\\output\\*",
            "ArtifactName": "drop",
            "ArtifactType": "FilePath",
            "TargetPath": "\\\\ic-tfs-fs-01\\TFSBuilds\\$(Build.DefinitionName)\\$(Build.BuildNumber)"
          }
        }
      ],
      "options": [
        {
          "enabled": false,
          "definition": {
            "id": "7c555368-ca64-4199-add6-9ebaf0b0137d"
          },
          "inputs": {
            "multipliers": "[]",
            "parallel": "false",
            "continueOnError": "true"
          }
        }
      ],
      "variables": {
        "BuildConfiguration": {
          "value": "debug",
          "allowOverride": true
        },
        "BuildPlatform": {
          "value": "any cpu",
          "allowOverride": true
        },
        "DNXPath": {
          "value": "C:\\Users\\tfs-build\\.dnx\\runtimes\\dnx-clr-win-x86.1.0.0-beta7-12335\\bin\\"
        }
      },
      "retentionRules": [
        {
          "branches": [
            "+refs/heads/*"
          ],
          "daysToKeep": 10,
          "deleteBuildRecord": true
        }
      ],
      "_links": {
        "self": {
          "href": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/b3284707-3d86-4bc7-b321-b22aee80daca/_apis/build/Definitions/22"
        },
        "web": {
          "href": "http://ic-tfs-at-01:8080/tfs/_permalink/_build/index?collectionId=0ea6f8c1-f923-47f0-b59a-af6d452d8f7f&projectId=b3284707-3d86-4bc7-b321-b22aee80daca&definitionId=22"
        }
      },
      "buildNumberFormat": "$(date:yyyyMMdd)$(rev:.r)",
      "createdDate": "2015-08-12T15:34:17.887Z",
      "jobAuthorizationScope": 1,
      "jobTimeoutInMinutes": 60,
      "repository": {
        "id": "ee7584f9-ba25-4535-9b5e-5038ec6a39c7",
        "type": "TfsGit",
        "name": "AspNet5",
        "url": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/BTE2015/_git/AspNet5",
        "defaultBranch": "refs/heads/master",
        "clean": "false",
        "checkoutSubmodules": true
      },
      "quality": 1,
      "authoredBy": {
        "id": "7f2b1ec7-224f-41de-b679-17e6ef28ce35",
        "displayName": "ICTFS-Admin",
        "uniqueName": "AZURE\\ICTFS-Admin",
        "url": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/_apis/Identities/7f2b1ec7-224f-41de-b679-17e6ef28ce35",
        "imageUrl": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/_api/_common/identityImage?id=7f2b1ec7-224f-41de-b679-17e6ef28ce35"
      },
      "queue": {
        "pool": null,
        "id": 1,
        "name": "default"
      },
      "uri": "vstfs:///Build/Definition/22",
      "type": 2,
      "revision": 6,
      "id": 22,
      "name": "ASP .NET 5 app",
      "url": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/b3284707-3d86-4bc7-b321-b22aee80daca/_apis/build/Definitions/22",
      "project": {
        "id": "b3284707-3d86-4bc7-b321-b22aee80daca",
        "name": "BTE2015",
        "url": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/_apis/projects/b3284707-3d86-4bc7-b321-b22aee80daca",
        "state": "wellFormed",
        "revision": 383343
    

    我怀疑问题在于您正在尝试使用 Visual Studio 测试适配器。

    【讨论】:

    • 感谢您的回答。虽然,这会将所有包放入本地文件夹,这违背了拥有全局包的目的。没有更好的解决方案吗?我们不能只在本地恢复测试适配器包吗?
    • 另外,vstest.console.exe 是否知道遍历整个packages 目录以获取测试适配器?我不需要指定xunit.runner.visualstudio.testadapter.dll 所在的确切文件夹吗?
    【解决方案2】:

    我在使用 NUnit 测试适配器查找正确路径时遇到了类似的问题,这是我在测试步骤中使用的最终对我有用的路径,也可能对您有用:

    "$(Build.SourcesDirectory)[你的包文件夹路径]\packages\NUnit3TestAdapter.3.8.0\build\netcoreapp1.0"

    测试适配器 dll 位于 netcoreapp1.0 文件夹中。此外,保留路径周围的引号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-19
      • 1970-01-01
      • 2016-06-04
      相关资源
      最近更新 更多