在VSTS中运行xunit.net测试

编程入门 行业动态 更新时间:2024-10-23 11:25:16
本文介绍了在VSTS中运行xunit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在VSTS中运行xunit测试时遇到问题.运行构建计划时,Test assemblies步骤将生成以下日志:

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作者:Microsoft Corporation 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_tasks \ VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9 \ 1.0.84 \ VSTest.ps1 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.6810971Z不存在. 2017-03-21T12:11:46.6820975Z 2017-03-21T12:11:46.6820975Z 2017-03-21T12:11:46.8520939Z工作文件夹: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)测试执行命令行工具版本14.0.25420.1 2017-03-21T12:11:47.2740881Z版权所有(c)微软公司.保留所有权利. 2017-03-21T12:11:47.2740881Z 2017-03-21T12:11:47.7430814Z正在开始执行测试,请稍候... 2017-03-21T12:12:01.0768912Z警告:[xUnit 00:00:01.1926376]跳过:MyClassLibrary.Tests(找不到以下任何程序集:xunit.execution.desktop.dll) 2017-03-21T12:12:01.0768912Z 2017-03-21T12:12:01.1458970Z警告:D:\ a \ 1 \ s \ Common.Tests \ bin \ Release \ MyClassLibrary.Tests.dll中没有可用的测试.确保已安装的测试发现者&执行者,平台和框架版本设置合适,然后重试.

该项目的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>

Test assemblies构建步骤中使用的值:

执行选项

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

高级执行选项

VSTest:Version VSTest版本:Latest

自定义适配器的路径为空,但工具提示显示为Nuget restored adapters are automatically searched for.

报告选项

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

在我看来,它可以找到正确的文件(MyClassLibrary.Tests.dll),但没有使用测试方法(标记为[Fact]或[Theory]的测试方法)./p>

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

更新

解决方案中的所有项目均为.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 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_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 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:\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: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 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:\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:

<?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测试

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

发布评论

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

>www.elefans.com

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