在未安装SDK的情况下运行xUnit测试 [英] Run xUnit tests without SDK installed

查看:44
本文介绍了在未安装SDK的情况下运行xUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在服务器上运行一些xUnit测试,而不必在该服务器上安装.NET Core SDK.

I would like to run some xUnit tests on a server, without having to install the .NET Core SDK there.

该服务器是安装了.NET Core运行时v2.2的Windows服务器.

The server is a Windows server with the .NET Core runtime v2.2 installed.

我将如何处理?

推荐答案

添加 xunit.控制台 nuget程序包(在编写本文时为2.4.1版),然后向您的程序中添加一个代码行.Main:

Add the xunit.console nuget package (version 2.4.1 at the time of writing), and add a one-liner to your Program.Main:

public class Program
{
    public static int Main()
    {
        return Xunit.ConsoleClient.Program.Main(
            new[] { typeof(Program).Assembly.Location });
    }
}

您还需要将< GenerateProgramFile> false</GenerateProgramFile> 添加到csproj文件中.

You will also need to add <GenerateProgramFile>false</GenerateProgramFile> to your csproj file.

只需使用 dotnet发布,就可以使用 dotnet运行"myapp.dll" 来执行测试.

Simply use dotnet publish, and you can use dotnet run "myapp.dll" to execute the tests.

如果需要灵活性,可以在需要时覆盖报告程序或过滤器,可以将其扩展为通过其他args.

You can extend this to pass through other args if you want flexibility to override reporters or filters if necessary.

似乎这些软件包尚未与其他xunit软件包一起更新(我认为这是v2版本-现在有v3),但这似乎仍适用于netcoreapp3.1和net5 xunit测试应用.

It seems these packages have not been updated along with other xunit packages (i think this is a v2 release - there is now a v3) but this still seems to work with netcoreapp3.1 and net5 xunit test apps.

这篇关于在未安装SDK的情况下运行xUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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