使用 xUnit 适配器在 TFS/VSO Build vNext 中运行单元测试 [英] Running unit tests in TFS/VSO Build vNext using xUnit adapter

查看:27
本文介绍了使用 xUnit 适配器在 TFS/VSO Build vNext 中运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

C:Usersuildagent.dnxpackagesxunit.runner.visualstudio2.1.0-beta4-build1109uild\_common

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

Executing C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe "C:a8ac4a4f6RootartifactsinMyProject.UnitTest
eleasednx451TransitApi.UnitTest.dll"/TestAdapterPath:C:Usersuildguest.dnxpackagesxunit.runner.visualstudio2.1.0-beta4-build1109uild\_common/UseVsixExtensions:true/记录器:trxMicrosoft (R) 测试执行命令行工具版本 14.0.23107.0版权所有 (c) 微软公司.版权所有.开始测试执行,请稍候...警告:C:a8ac4a4f6RootartifactsinMyProject.UnitTest
eleasednx451TransitApi.UnitTest.dll 中没有可用的测试.确保已安装测试发现者 &执行者、平台和框架版本设置合适,然后重试.未找到可发布的结果.

project.json,如果相关:

依赖项":{"xunit": "2.1.0-beta4-build3109","xunit.runner.dnx": "2.1.0-beta4-build134","xunit.runner.visualstudio": "2.1.0-beta4-build1109"},命令":{测试":xunit.runner.dnx"},构架": {dnx451":{}}

解决方案

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

<代码>{包裹":包裹"}

这将强制您的 dnu restore 将包放入 .packages,这有望解决问题.只需将测试适配器路径指定为 $(Build.SourcesDirectory)packages - 您可能必须指定完整的程序集名称,我不确定是否过头.

<小时>

更新:我采用了示例HelloMvc"应用程序,并在没有 global.json 的情况下使用 xUnit 测试构建它.这是我的构建定义:

<代码>{建造": [{启用":真,continueOnError":假,始终运行":假,"displayName": "恢复包",任务": {"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",版本规范":*"},输入":{"文件名": "$(DNXPath)\dnu.cmd","参数": "恢复",工作文件夹":",failOnStandardError":假"}},{启用":真,continueOnError":假,始终运行":假,"displayName": "运行测试",任务": {"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",版本规范":*"},输入":{"文件名": "$(DNXPath)\dnx.exe",参数":测试",工作文件夹":",failOnStandardError":假"}},{启用":真,continueOnError":假,始终运行":假,"displayName": "构建 NuGet 包",任务": {"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",版本规范":*"},输入":{"文件名": "$(DNXPath)\dnu.cmd","参数": "发布",工作文件夹":",failOnStandardError":假"}},{启用":真,continueOnError":假,始终运行":假,"displayName": "发布神器:掉落",任务": {"id": "1d341bb0-2106-458c-8422-d00bcea6512a",版本规范":*"},输入":{"复制根": "","内容": "**\输出\*","ArtifactName": "掉落","ArtifactType": "文件路径","TargetPath": "\\ic-tfs-fs-01\TFSBuilds\$(Build.DefinitionName)\$(Build.BuildNumber)"}}],选项": [{启用":假,定义": {"id": "7c555368-ca64-4199-add6-9ebaf0b0137d"},输入":{"乘数": "[]",平行":假",continueOnError":真"}}],变量":{构建配置":{值":调试",允许覆盖":真},构建平台":{"value": "任何 CPU",允许覆盖":真},DNXPath":{"value": "C:\Users\tfs-build\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7-12335\bin\"}},保留规则":[{分支":[+ refs/heads/*"],"daysToKeep": 10,"deleteBuildRecord": 真}],_links":{自己": {"href": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/b3284707-3d86-4bc7-b321-b22aee80daca/_apis/build/Definitions/22"},网络":{href":http://ic-tfs-at-01:8080/tfs/_permalink/_build/index?collectionId=0ea6f8c1-f923-47f0-b59a-af6d452d8f7f&projectId=b3284707-3d82b24ab3d86-b24abee;定义ID=22"}},"buildNumberFormat": "$(date:yyyyMMdd)$(rev:.r)","createdDate": "2015-08-12T15:34:17.887Z","jobAuthorizationScope": 1,"jobTimeoutInMinutes": 60,存储库":{"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",干净":假","checkoutSubmodules": 真},质量":1,作者":{"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"},队列": {池":空,身份证":1,名称":默认"},"uri": "vstfs:///Build/Definition/22",类型":2,修订":6,身份证":22,"name": "ASP .NET 5 应用程序","url": "http://ic-tfs-at-01:8080/tfs/InCycleEventsCollection/b3284707-3d86-4bc7-b321-b22aee80daca/_apis/build/Definitions/22",项目": {"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",修订":383343

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

I am trying to run our xUnit tests using the xUnit test adapter in Visual Studio Online's Build vNext platform.

As stipulated in this article, we need to provide a custom test adapter path pointing to xunit.runner.visualstudio.testadapter.dll.

But this package is restored by NuGet to a global packages folder, namely C:Users{user}.dnxpackages?

How am I to reference this folder in the build step?

We are using VS 2015 and DNX projects.

EDIT:

I even tried pointing to the package path DLL directly:

C:Usersuildagent.dnxpackagesxunit.runner.visualstudio2.1.0-beta4-build1109uild\_common

It still did not seem to use the adapter:

Executing C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe "C:a8ac4a4f6RootartifactsinMyProject.UnitTest
eleasednx451TransitApi.UnitTest.dll"  /TestAdapterPath:C:Usersuildguest.dnxpackagesxunit.runner.visualstudio2.1.0-beta4-build1109uild\_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:a8ac4a4f6RootartifactsinMyProject.UnitTest
eleasednx451TransitApi.UnitTest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
No results found to publish.

The project.json, if relevant:

"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": { }
}

解决方案

Make a global.json file and put the following into it:

{
  "packages": "packages"
}

That will force your dnu restore to put the packages into .packages, which will hopefully solve the problem. Just specify the test adapter path as $(Build.SourcesDirectory)packages -- you may have to specify the full assembly name, I'm not sure off the top of my head.


Update: I took the sample "HelloMvc" application and got it to build with xUnit tests without a global.json. Here's my build definition:

{
  "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

I suspect that the problem is that you're trying to use the Visual Studio test adapter.

这篇关于使用 xUnit 适配器在 TFS/VSO Build vNext 中运行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆