[英]How to run TestFixture programatically with NUnit3
我一直在嘗試找到一種以編程方式運行TestFixture的好方法,但似乎找不到使用NUnit3的方法。 我關注了這篇文章,但它似乎對我不起作用,似乎正在運行我可能沒有的特定測試或測試列表,我所擁有的只是TestFixture類的名稱。
我還閱讀了幾篇非常古老的文章,並提到使用我收集的TestRunner和TestPackage之類的東西在NUnit3中不再可用。 我可以使用命令行和nunit3-console運行/執行測試類,這是我應該在此處從程序中調用可執行文件的方法嗎?
絕對可以直接引用NUnitLite並創建一個Main程序來運行測試。 您必須使用相同版本的nunit框架和nUnitlite程序集才能起作用。
NUnitLite的AutoRun測試運行程序的調用順序因版本而異。 您可以使用intellisense進行檢查。 對於3.9,請使用如下代碼:
new AutoRun().Execute(args);
筆記:
args
是傳遞到測試可執行文件中的同一參數數組。 new string[] { "--test:Name.Of.MyFixture" }
來運行燈具。 我假設解決此問題的理想方法是使用NUnitLite AutoRun,但我無法使其正常運行,因此我選擇了通過Process調用nunit3-console的選項。
string nunit = @"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe";
string assembly = @"C:\Path\to\assembly.dll";
string testFixture = " --where class=" + fixtureToRun;
string work = @" --work=C:\Path\to\store\results\";
string args = assembly + testFixture + work;
ProcessStartInfo processStartInfo = new ProcessStartInfo(nunit, args);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
using (Process process = new Process())
{
process.StartInfo = processStartInfo;
process.Start();
bool completed = process.WaitForExit(60000);
string result = process.StandardOutput.ReadToEnd();
Console.WriteLine(result);
}
希望這可以幫助某人,我仍然願意以更有效的方式提出建議
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.