gpt4 book ai didi

asp.net-core - 在 Visual Studio Team Services 托管代理上构建的 ASP.Net Core 1.0 项目上未发现使用 xUnit 的测试

转载 作者:行者123 更新时间:2023-12-01 14:36:01 26 4
gpt4 key购买 nike

我遇到一个问题,在 Visual Studio Team Services 上构建时,我的 ASP.Net Core 1.0 应用程序中的 xUnit 测试没有被发现。

测试项目正在构建成功,但是没有给出测试结果。我在日志中找到以下有关 Visual Studio 测试步骤的消息:

******************************************************************************
Starting task: Test Assemblies **\*test*.dll;-:**\xunit.runner.visualstudio.testadapter.dll
******************************************************************************
Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\VSTest\1.0.29\VSTest.ps1
Working folder: C:\a\1
Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\a\1\s\artifacts\bin\project.test\Debug\dnx451\project.test.dll" /EnableCodeCoverage /InIsolation /logger:trx
Microsoft (R) Test Execution Command Line Tool Version 14.0.24720.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Warning: No test is available in C:\a\1\s\artifacts\bin\project.test\Debug\dnx451\project.test.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
Attachments:
C:\a\1\TestResults\0ad44b11-4dd4-41ba-a0bf-66d9cd487a3c\buildguest_TASKAGENT5-0007 2016-03-01 07_33_04.coverage
Information: Additionally, you can try specifying '/UseVsixExtensions' command if the test discoverer & executor is installed on the machine as vsix extensions and your installation supports vsix extensions. Example: vstest.console.exe myTests.dll /UseVsixExtensions:true
No results found to publish.

测试是这样写的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Xunit;

namespace project.tests
{
public class ProjectTests
{
[Fact]
public void PassingTest()
{
Assert.Equal(4, Add(2, 2));
}

[Fact]
public void FailingTest()
{
Assert.Equal(5, Add(2, 2));
}

int Add(int x, int y)
{
return x + y;
}
}
}

测试在本地运行良好,但在 Visual Studio Team Services 上运行不佳。

作为引用,这是我的 project.json

{
"authors": [ "Tom Reiertsen" ],
"commands": {
"test": "xunit.runner.dnx"
},
"dependencies": {
"project": "1.0.0-rc1-update1",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
"Microsoft.AspNet.TestHost": "1.0.0-rc1-final",
"Microsoft.AspNet.WebApi.Client": "5.2.3",
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204",
"xunit.runner.visualstudio": "2.1.0"
},
"description": "project.test Class Library",
"frameworks": {
"dnx451": { }
},
"licenseUrl": "",
"projectUrl": "",
"tags": [ "" ],
"version": "1.0.0-rc1-update1"
}

最佳答案

在“Advanced Execution Options\Path to Custom Test Adapters”中输入“$(Build.SourcesDirectory)\SolutionFolderName\packages”,将测试适配器设置为xUnit。有关详细信息,请参阅此链接:xUnit or NUnit with Visual Studio Online Build

更新:我只是创建了一个示例应用程序来测试它并与您一起遇到同样的问题。但是,如果我将 xunit 程序集文件与 test.dll 一起复制到“dnx451”文件夹中,测试将成功完成。 enter image description here enter image description here

并且由于您正在处理 Asp.Net Core 项目并已导入 DNX 运行器,因此您还可以添加“命令行”任务以使用 dnx 测试命令直接运行测试。 enter image description here

关于asp.net-core - 在 Visual Studio Team Services 托管代理上构建的 ASP.Net Core 1.0 项目上未发现使用 xUnit 的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35717290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com