I would like to run some xUnit tests on a server, without having to install the .NET Core SDK there.
The server is a Windows server with the .NET Core runtime v2.2 installed.
How would I go about this?
I would like to run some xUnit tests on a server, without having to install the .NET Core SDK there.
The server is a Windows server with the .NET Core runtime v2.2 installed.
How would I go about this?
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 });
}
}
You will also need to add <GenerateProgramFile>false</GenerateProgramFile>
to your csproj file.
Simply use dotnet publish
, and you can use dotnet run "myapp.dll"
to execute the tests.
You can extend this to pass through other args if you want flexibility to override reporters or filters if necessary.
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.