C# 如何从命令行运行NUnit并获取xml结果文件?

C# 如何从命令行运行NUnit并获取xml结果文件?,c#,xml,nunit,C#,Xml,Nunit,我在c#中有以下代码: 我想在测试结束后将测试结果保存到xml文件中。如何解决这个问题 看起来您正在直接使用console runner,如果是这种情况,那么默认情况下,它将在每次运行时生成一个Xml文件。它以名称TestResult.xml将其写入工作目录,因此如果您只想将文件保存到某个位置,只需执行以下操作: // Run the test like you're currently doing NUnit.ConsoleRunner.Runner.Main(new string[] {

我在c#中有以下代码:


我想在测试结束后将测试结果保存到xml文件中。如何解决这个问题

看起来您正在直接使用console runner,如果是这种情况,那么默认情况下,它将在每次运行时生成一个Xml文件。它以名称
TestResult.xml
将其写入工作目录,因此如果您只想将文件保存到某个位置,只需执行以下操作:

// Run the test like you're currently doing
NUnit.ConsoleRunner.Runner.Main(new string[]
{
   System.Reflection.Assembly.GetExecutingAssembly().Location,
   "OpenShop.dll",                   
});

// Save the file to match the name of the assembly, and so it is not
// overwritten on each run
File.Copy("TestResult.xml", "OpenShop-TestResult.xml");

您需要像这样以编程方式运行测试吗?或者您可以使用内置的控制台运行程序--
nunit console.exe
,它已经生成Xml输出了吗?我需要以编程方式执行此操作,因为我正在构建一个自动运行测试的应用程序。
// Run the test like you're currently doing
NUnit.ConsoleRunner.Runner.Main(new string[]
{
   System.Reflection.Assembly.GetExecutingAssembly().Location,
   "OpenShop.dll",                   
});

// Save the file to match the name of the assembly, and so it is not
// overwritten on each run
File.Copy("TestResult.xml", "OpenShop-TestResult.xml");