简体   繁体   English

在VSTS中运行xunit.net测试

[英]Running xunit.net tests in VSTS

I have an issue running xunit.net tests in VSTS . 我在VSTS运行xunit.net测试时遇到问题。 When running the Build plan, the Test assemblies step produces the following log: 运行构建计划时,“ Test assemblies步骤将生成以下日志:

2017-03-21T12:11:39.3302859Z ##[section]Starting: Test Assemblies 2017-03-21T12:11:39.3302859Z ## [section]开始:测试程序集
2017-03-21T12:11:39.3382932Z ============================================================================== 2017-03-21T12:11:39.3382932Z ======================================= =====================================
2017-03-21T12:11:39.3382932Z Task : Visual Studio Test 2017-03-21T12:11:39.3382932Z任务:Visual Studio测试
2017-03-21T12:11:39.3382932Z Description : Run tests with Visual Studio test runner 2017-03-21T12:11:39.3382932Z说明:使用Visual Studio测试运行器运行测试
2017-03-21T12:11:39.3382932Z Version : 1.0.84 2017-03-21T12:11:39.3382932Z版本:1.0.84
2017-03-21T12:11:39.3382932Z Author : Microsoft Corporation 2017-03-21T12:11:39.3382932Z作者:微软公司
2017-03-21T12:11:39.3382932Z Help : More Information 2017-03-21T12:11:39.3382932Z帮助: 更多信息
2017-03-21T12:11:39.3382932Z ============================================================================== 2017-03-21T12:11:39.3382932Z ======================================= =====================================
2017-03-21T12:11:39.3493151Z Preparing task execution handler. 2017-03-21T12:11:39.3493151Z准备任务执行处理程序。
2017-03-21T12:11:44.9245238Z Executing the powershell script: D:\\a_tasks\\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\\1.0.84\\VSTest.ps1 2017-03-21T12:11:44.9245238Z执行Powershell脚本:D:\\ a_tasks \\ VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9 \\ 1.0.84 \\ VSTest.ps1
2017-03-21T12:11:46.6530959Z Testing container: 'REGISTRY::HKEY_CLASSES_ROOT\\CLSID{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}' 2017-03-21T12:11:46.6530959Z测试容器:“ REGISTRY :: HKEY_CLASSES_ROOT \\ CLSID {177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}”
2017-03-21T12:11:46.6530959Z 2017-03-21T12:11:46.6530959Z
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.6810971Z不存在
2017-03-21T12:11:46.6820975Z 2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.6820975Z 2017-03-21T12:11:46.6820975Z
2017-03-21T12:11:46.8520939Z Working folder: D:\\a\\1\\s 2017-03-21T12:11:46.8520939Z工作文件夹:D:\\ a \\ 1 \\ s
2017-03-21T12:11:46.8520939Z Executing C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow\\vstest.console.exe "D:\\a\\1\\s\\Common.Tests\\bin\\Release\\MyClassLibrary.Tests.dll" /Settings:"C:\\Users\\buildguest\\AppData\\Local\\Temp\\tmp89AE.tmp" /EnableCodeCoverage /logger:trx /TestAdapterPath:"D:\\a\\1\\s" 2017-03-21T12:11:46.8520939Z正在执行C:\\ Program Files(x86)\\ Microsoft Visual Studio 14.0 \\ Common7 \\ IDE \\ CommonExtensions \\ Microsoft \\ TestWindow \\ vstest.console.exe“ D:\\ a \\ 1 \\ s \\ Common.Tests \\ bin \\ Release \\ MyClassLibrary.Tests.dll“ /设置:” C:\\ Users \\ buildguest \\ AppData \\ Local \\ Temp \\ tmp89AE.tmp“ / EnableCodeCoverage / logger:trx / TestAdapterPath:” D:\\ a \\ 1 \\ s“
2017-03-21T12:11:47.2730887Z Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1 2017-03-21T12:11:47.2730887Z Microsoft(R)测试执行命令行工具版本14.0.25420.1
2017-03-21T12:11:47.2740881Z Copyright (c) Microsoft Corporation. 2017-03-21T12:11:47.2740881Z版权所有(c)微软公司。 All rights reserved. 版权所有。
2017-03-21T12:11:47.2740881Z 2017-03-21T12:11:47.2740881Z
2017-03-21T12:11:47.7430814Z Starting test execution, please wait... 2017-03-21T12:11:47.7430814Z正在开始执行测试,请稍候...
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警告:[xUnit.net 00:00:01.1926376]跳过:MyClassLibrary.Tests(找不到以下任何程序集:xunit.execution.desktop.dll)
2017-03-21T12:12:01.0768912Z 2017-03-21T12:12:01.0768912Z
2017-03-21T12:12:01.1458970Z Warning: No test is available in D:\\a\\1\\s\\Common.Tests\\bin\\Release\\MyClassLibrary.Tests.dll. 2017-03-21T12:12:01.1458970Z警告:D:\\ a \\ 1 \\ s \\ Common.Tests \\ bin \\ Release \\ MyClassLibrary.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: 该项目的packages.config文件是这样的:

<?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: Test assemblies构建步骤中使用的值:

Execution options 执行选项

Test assembly: **\\*Tests.dll;-:**\\obj\\** 测试程序集: **\\*Tests.dll;-:**\\obj\\**
Code coverage enabled: true 启用代码覆盖率: true

Advanced Execution options 高级执行选项

VSTest: Version VSTest: Version
VSTest version: Latest VSTest版本: Latest

Path to custom adapters is empty, but the tooltip states Nuget restored adapters are automatically searched for. 自定义适配器的路径为空,但是工具提示Nuget restored adapters are automatically searched for.

Reporting options 报告选项

Platform: $(BuildPlatform) 平台: $(BuildPlatform)
Configuration: $(BuildConfiguration) 配置: $(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 ]). 因此,在我看来,它可以找到正确的文件(MyClassLibrary.Tests.dll),但没有使用测试方法(标记为[Fact][Theory ])。

Anybody has an idea what I do wrong? 有人知道我做错了什么吗?

update 更新

All projects in the solution are .NET 4.5 解决方案中的所有项目均为.NET 4.5

Just an update on this as I've recently also had this issue and couldn't get the VsTest runner to discover my .net Core 2.0 xunit tests. 只是对此的更新,因为我最近也遇到了这个问题,无法让VsTest运行程序发现我的.net Core 2.0 xunit测试。

Note: VsTest runner works fine locally on my machine, but not from VSTS - even though xunit test adapters are there. 注意:即使有xunit测试适配器,VsTest运行程序在我的计算机上本地也可以正常运行,但不能在VSTS上运行。

In any case, use the .NET Core build task instead - it's pretty easy to use. 无论如何,请改用.NET Core构建任务 -相当容易使用。 Basically: 基本上:

  1. Add .Net Core build task (preview atm) 添加.Net Core构建任务(预览atm)
  2. Select desired .NET Core version 选择所需的.NET Core版本
  3. Change command to test 更改命令进行测试
  4. Add path or paths to your test projects - eg **/*Tests.csproj 为您的测试项目添加一个或多个路径-例如** / * Tests.csproj
  5. Any additional arguments - eg --filter "Category!=Integration" 任何其他参数-例如--filter“ Category!= Integration”
  6. There's also a Publish test results option that'll create trx output file 还有一个发布测试结果选项,它将创建trx输出文件

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). 经过大量的反复试验和搜索后,我切换到xUnit后遇到了同样的问题,我发现xUnit测试运行程序只能在面向.NET 4.5.2或更高版本的程序集中运行,否则不能已加载(因此将找不到测试)。

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)" . 这里的文档有点含糊,因为xUnit入门指南并没有真正提到这一点,它只提到了创建一个新的类库项目“目标是.NET 4.5.2(或更高版本)”

But this is only for the assembly containing the actual tests, your projects being tested can still target .NET 4.5. 但这仅适用于包含实际测试的程序集,正在测试的项目仍可以针对.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. 就我而言,我只是将测试程序集切换到.NET 4.5.2,但是所有其他项目仍然以.NET 4.5为目标,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM