XUnit 使用 Cake 处理 .NET Core [英] XUnit working with .NET Core using Cake

查看:26
本文介绍了XUnit 使用 Cake 处理 .NET Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对简单的解决方案.在 MSBuild 下一切正常(在 VS 2017 Mac 中).我正在创建一个 Cake 构建脚本,但我无法让单元测试工作.有很多例子,但似乎没有一个是有效的.有些人呼吁 DotnetCoreTest,大多数人呼吁 XUnit2.在我的项目中根本没有工作.

I have a relatively simple solution. All works fine under MSBuild (in VS 2017 Mac). I'm creating a Cake build script, but I just cannot get unit testing to work. There are tons of examples, but it seems that none are valid anymore. Some call for DotnetCoreTest, most for XUnit2. Neither work at all in my project.

我在运行 XUnit2 时收到以下错误:System.InvalidOperationException: Unknown test framework: could not find xunit.dll (v1) or xunit.execution.*.dll (v2) in/Users/dev/Projects/MyProject/tst/MyProject.Serialization.UnitTests/bin/Release/netcoreapp1.1

I get the following error when running XUnit2: System.InvalidOperationException: Unknown test framework: could not find xunit.dll (v1) or xunit.execution.*.dll (v2) in /Users/dev/Projects/MyProject/tst/MyProject.Serialization.UnitTests/bin/Release/netcoreapp1.1

而且那个输出是绝对有效的,文件实际上不在那里.以下是我的单元测试项目的参考资料:

And that output is absolutely valid, the file is in fact not there. Here are the references for my unit test project:

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
    <PackageReference Include="xunit.runner.console" Version="2.2.0" />
    <PackageReference Include="FluentAssertions" Version="4.19.2" />
    <PackageReference Include="Moq" Version="4.7.99" />
    <PackageReference Include="FluentAssertions.AspNetCore.Mvc" Version="0.7.0-beta1" />
    <PackageReference Include="AutoMapper" Version="6.1.1" />
    <PackageReference Include="ExpectedObjects" Version="1.3.0" />
    <PackageReference Include="OpenCover" Version="4.6.519" />
    <PackageReference Include="xunit.extensibility.execution" Version="2.2.0" />
</ItemGroup>

我已经引用了 xunit.runner.consolexunit.extensibility.execution,但这些都没有复制到目标目录..NET Core 似乎没有办法强制这样做,即使我手动复制它们,测试程序集仍然不会加载.

I have referenced xunit.runner.console AND xunit.extensibility.execution, yet these are not copied to the destination directory. .NET Core doesn't appear to have any way to force that, and even if I copy them manually the test assemblies still won't load.

这是我的蛋糕测试脚本:

Here is my Cake Test script:

#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0
#tool nuget:?package=xunit.runner.console
...
Task("Test")
    .IsDependentOn("Build")
    .Does(() =>
{
    Information("Start Running Tests");
    XUnit2(string.Format("./tst/**/*Tests/bin/{0}/**/*Tests.dll", configuration), new XUnit2Settings
    {
    });
});

显然我遗漏了一些非常基本的东西,但是由于所有相互矛盾的信息,我不知道它是什么.我不应该使用 XUnit 吗?

Clearly I'm missing something very basic, but with all the conflicting information out there I don't know what it is. Should I not be using XUnit?

推荐答案

我遇到了同样的问题,通过使用 DotNetCoreTest 而不是 XUnit2 来解决.

I encounter the same issue, resolve it by using DotNetCoreTest instead of XUnit2.

Task("Test")
    .Does(() => 
    {
        DotNetCoreTest("./test/[TestProjectPath]/[TestProject.csproj]");
    });

这篇关于XUnit 使用 Cake 处理 .NET Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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