使用xUnit适配器在TFS/VSO Build vNext中运行单元测试

编程入门 行业动态 更新时间:2024-10-23 13:23:11
本文介绍了使用xUnit适配器在TFS/VSO Build vNext中运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

根据本文,我们需要提供一个指向xunit.runner.visualstudio.testadapter.dll的自定义测试适配器路径.

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

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

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

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

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

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

We are using VS 2015 and DNX projects.

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

I even tried pointing to the package path DLL directly:

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

它似乎仍未使用适配器:

It still did not seem to use the adapter:

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

推荐答案

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

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

{ "packages": "packages" }

这将迫使您的dnu restore将软件包放入.\packages\中,有望解决该问题.只需将测试适配器的路径指定为$(Build.SourcesDirectory)\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.

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

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": "ic-tfs-at-01:8080/tfs/InCycleEventsCollection/b3284707-3d86-4bc7-b321-b22aee80daca/_apis/build/Definitions/22" }, "web": { "href": "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": "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": "ic-tfs-at-01:8080/tfs/InCycleEventsCollection/_apis/Identities/7f2b1ec7-224f-41de-b679-17e6ef28ce35", "imageUrl": "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": "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": "ic-tfs-at-01:8080/tfs/InCycleEventsCollection/_apis/projects/b3284707-3d86-4bc7-b321-b22aee80daca", "state": "wellFormed", "revision": 383343

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

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

更多推荐

使用xUnit适配器在TFS/VSO Build vNext中运行单元测试

本文发布于:2023-11-08 14:10:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适配器   单元测试   TFS   xUnit   vNext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!