在 VSTS 中运行 xunit.net 测试 [英] Running xunit.net tests in VSTS

查看:18
本文介绍了在 VSTS 中运行 xunit.net 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VSTS 中运行 xunit.net 测试时遇到问题.运行构建计划时,测试程序集 步骤会生成以下日志:

<块引用>

2017-03-21T12:11:39.3302859Z ##[section]开始:测试程序集
2017-03-21T12:11:39.3382932Z ==============================================================================
2017-03-21T12:11:39.3382932Z 任务:Visual Studio 测试
2017-03-21T12:11:39.3382932Z 描述:使用 Visual Studio 测试运行器运行测试
2017-03-21T12:11:39.3382932Z 版本:1.0.84
2017-03-21T12:11:39.3382932Z 作者:微软公司
2017-03-21T12:11:39.3382932Z 帮助:更多信息
2017-03-21T12:11:39.3382932Z ==============================================================================
2017-03-21T12:11:39.3493151Z 准备任务执行处理程序.
2017-03-21T12:11:44.9245238Z 执行 powershell 脚本:D:a_tasksVSTest_ef087383-ee5e-42c7-9a53-ab56c98420f91.0.84VSTest.ps1
2017-03-21T12:11:46.6530959Z 测试容器:'REGISTRY::HKEY_CLASSES_ROOTCLSID{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'
2017-03-21T12:11:46.6530959Z
2017-03-21T12:11:46.6530959Z
2017-03-21T12:11:46.6810971Z 不存在.
2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.8520939Z 工作文件夹:D:a1s
2017-03-21T12:11:46.8520939Z 执行 C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe "D:a1sCommon.TestsinReleaseMyClassLibrary.Tests.dll"/Settings:"C:UsersuildguestAppDataLocalTemp mp89AE.tmp"/EnableCodeCoverage/logger:trx/TestAdapterPath:"D:a1s"
2017-03-21T12:11:47.2730887Z Microsoft (R) 测试执行命令行工具版本 14.0.25420.1
2017-03-21T12:11:47.2740881Z 版权所有 (c) Microsoft Corporation.保留所有权利.
2017-03-21T12:11:47.2740881Z
2017-03-21T12:11:47.7430814Z 开始测试执行,请稍候...
2017-03-21T12:12:01.0768912Z 警告:[xUnit.net 00:00:01.1926376] 跳过:MyClassLibrary.Tests(找不到以下任何程序集:xunit.execution.desktop.dll)
2017-03-21T12:12:01.0768912Z
2017-03-21T12:12:01.1458970Z 警告:D:a1sCommon.TestsinReleaseMyClassLibrary.Tests.dll 中没有可用的测试.确保已安装测试发现者 &执行者、平台和框架版本设置合适,然后重试.

这个项目的 packages.config 文件是这样的:

<前><?xml version="1.0";编码=utf-8"?><包>...<package id="xunit";版本=2.2.0";targetFramework="net45";/><package id="xunit.abstractions";版本=2.0.1"targetFramework="net45";/><package id="xunit.assert";版本=2.2.0";targetFramework="net45";/><package id="xunit.core";版本=2.2.0";targetFramework="net45";/><package id="xunit.extensibility.core";版本=2.2.0";targetFramework="net45";/><package id="xunit.extensibility.execution";版本=2.2.0";targetFramework="net45";/><package id="xunit.runner.msbuild";版本=2.1.0";targetFramework="net45";/><package id="xunit.runner.visualstudio";版本=2.2.0";targetFramework="net45";developmentDependency=真"/></包>

测试程序集构建步骤中使用的值:

执行选项

测试程序集:***Tests.dll;-:**obj**
启用代码覆盖:true

高级执行选项

VSTest:版本
VSTest 版本:最新

自定义适配器的路径为空,但工具提示指出自动搜索 Nuget 恢复的适配器.

报告选项

平台:$(BuildPlatform)
配置:$(BuildConfiguration)

所以它似乎(对我来说)它可以找到正确的文件(MyClassLibrary.Tests.dll),但没有选择测试方法(标记为 [Fact][理论]).

有人知道我做错了什么吗?

更新

解决方案中的所有项目都是.NET 4.5

解决方案

我在切换到 xUnit 后遇到了同样的问题,经过多次反复试验和搜索,我发现 xUnit 测试运行程序只能在面向 .NET 4.5.2 或更高版本的程序集中运行,否则无法加载(因此将找不到测试).

这里的文档有点模糊,因为 xUnit 入门 指南并没有真正提到这一点,它只提到创建一个新的类库项目针对 .NET 4.5.2(或更高版本)".

但这仅适用于包含实际测试的程序集,您正在测试的项目仍然可以面向 .NET 4.5.就我而言,我只是将我的测试程序集切换到面向 .NET 4.5.2,但所有其他项目仍然面向 .NET 4.5,并且运行良好.

I have an issue running xunit.net tests in VSTS. When running the Build plan, the Test assemblies step produces the following log:

2017-03-21T12:11:39.3302859Z ##[section]Starting: Test Assemblies
2017-03-21T12:11:39.3382932Z ==============================================================================
2017-03-21T12:11:39.3382932Z Task : Visual Studio Test
2017-03-21T12:11:39.3382932Z Description : Run tests with Visual Studio test runner
2017-03-21T12:11:39.3382932Z Version : 1.0.84
2017-03-21T12:11:39.3382932Z Author : Microsoft Corporation
2017-03-21T12:11:39.3382932Z Help : More Information
2017-03-21T12:11:39.3382932Z ==============================================================================
2017-03-21T12:11:39.3493151Z Preparing task execution handler.
2017-03-21T12:11:44.9245238Z Executing the powershell script: D:a_tasksVSTest_ef087383-ee5e-42c7-9a53-ab56c98420f91.0.84VSTest.ps1
2017-03-21T12:11:46.6530959Z Testing container: 'REGISTRY::HKEY_CLASSES_ROOTCLSID{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'
2017-03-21T12:11:46.6530959Z
2017-03-21T12:11:46.6530959Z
2017-03-21T12:11:46.6810971Z Does not exist.
2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.8520939Z Working folder: D:a1s
2017-03-21T12:11:46.8520939Z Executing C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe "D:a1sCommon.TestsinReleaseMyClassLibrary.Tests.dll" /Settings:"C:UsersuildguestAppDataLocalTemp mp89AE.tmp" /EnableCodeCoverage /logger:trx /TestAdapterPath:"D:a1s"
2017-03-21T12:11:47.2730887Z Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
2017-03-21T12:11:47.2740881Z Copyright (c) Microsoft Corporation. All rights reserved.
2017-03-21T12:11:47.2740881Z
2017-03-21T12:11:47.7430814Z Starting test execution, please wait...
2017-03-21T12:12:01.0768912Z Warning: [xUnit.net 00:00:01.1926376] Skipping: MyClassLibrary.Tests (Could not find any of the following assemblies: xunit.execution.desktop.dll)
2017-03-21T12:12:01.0768912Z
2017-03-21T12:12:01.1458970Z Warning: No test is available in D:a1sCommon.TestsinReleaseMyClassLibrary.Tests.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

The packages.config file for this project is this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  ...
  <package id="xunit" version="2.2.0" targetFramework="net45" />
  <package id="xunit.abstractions" version="2.0.1" targetFramework="net45" />
  <package id="xunit.assert" version="2.2.0" targetFramework="net45" />
  <package id="xunit.core" version="2.2.0" targetFramework="net45" />
  <package id="xunit.extensibility.core" version="2.2.0" targetFramework="net45" />
  <package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net45" />
  <package id="xunit.runner.msbuild" version="2.1.0" targetFramework="net45" />
  <package id="xunit.runner.visualstudio" version="2.2.0" targetFramework="net45" developmentDependency="true" />
</packages>

The values used in the Test assemblies build step:

Execution options

Test assembly: ***Tests.dll;-:**obj**
Code coverage enabled: true

Advanced Execution options

VSTest: Version
VSTest version: Latest

Path to custom adapters is empty, but the tooltip states Nuget restored adapters are automatically searched for.

Reporting options

Platform: $(BuildPlatform)
Configuration: $(BuildConfiguration)

So it seems (to me) that it can find the proper file (MyClassLibrary.Tests.dll), but doesn't pick up the test methods (which are marked as [Fact] or [Theory]).

Anybody has an idea what I do wrong?

update

All projects in the solution are .NET 4.5

解决方案

I had the same issue once I made the switch to xUnit, after lots of trial-and-error and searching I found that the xUnit test runner can only be run in an assembly targeting .NET 4.5.2 or above, otherwise it cannot be loaded (and thus the tests will not be found).

The documentation is a bit vague here, since the Getting Started with xUnit guide doesn't really mention this, it only mentions to create a new class library project "targeting .NET 4.5.2 (or later)".

But this is only for the assembly containing the actual tests, your projects being tested can still target .NET 4.5. In my case I simply switched my test assemblies to target .NET 4.5.2, but all the other projects still target .NET 4.5 and it works very well.

这篇关于在 VSTS 中运行 xunit.net 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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