简体   繁体   中英

How I can run NUnit from command line and get xml result file?

I have following code in c#:

NUnit.ConsoleRunner.Runner.Main(new string[]
{
   System.Reflection.Assembly.GetExecutingAssembly().Location,
   "OpenShop.dll",                   
});

And I want to save result from this test to xml file after test ends. How to solve this problem?

It appears you're using the console runner directly, which if that's the case then by default it will generate an Xml file on each run. It writes it to the working directory with the name TestResult.xml , so if you just want to save the file somewhere you'd just need to do this:

// 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM