簡體   English   中英

指定要運行的NUnit測試

[英]specify NUnit test to run

我有一個NUnit項目,用於創建用於運行測試的控制台應用程序。 入口點如下所示:

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        string[] my_args = { Assembly.GetExecutingAssembly().Location };

        int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args);

        if (returnCode != 0)
            Console.Beep();

    }
}

如果我只想運行這個測試,我可以作為參數傳遞什么:

[TestFixture]
public class EmailNotificationTest
{
    [Test]
    public void MailerDefaultTest()
    {
        Assert.IsTrue(false);
    }
}

顯然這是支持的,同樣明顯我不知道如何做到這一點。

UPDATE

看起來像v3 +, 根據文檔可以使用--test選項。

最新版本(NUnit 3)允許調試測試並指定執行測試。

調試

--debug選項啟動調試器以調試測試,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug

過濾測試

現在,您有多種不同的方法可以選擇要運行的測試。 第一個選項是--test=NAMES 結合此選項和--debug您只需輕松調試一個測試,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug --test="EmailNotificationTest.MailerDeSecondTest" 

如果類具有它,請不要忘記命名空間。

使用--testlist=PATH選項,您可以運行文件中指定的所有測試,例如:

nunit3-console.exe "C:\path\to\the\tests.dll" --debug --testlist="testnames.txt" 

還有--where=EXPRESSION選項,指示將運行哪些測試。 此選項旨在擴展或替換早期的--test , - --include--exclude選項。 如果您想了解有關此選項的更多信息,請查看官方文檔

您可以使用[Category("RunOnlyThis")]屬性標記測試,然后告訴NUnit運行僅匹配此特定類別的測試:

 /include:RunOnlyThis

是您需要添加到控制台運行程序參數的屬性。 更多這里

您可以使用/運行 NUnit控制台的開關來指定要運行的測試。

像這樣:

/run:namespace.classname.functionName

例如

nunit-console.exe "C:\UnitTests.dll" /run:UnitTests.EmailNotificationTest.MailerDefaultTest

正如@Toto所說,使用NUnit Gui ,你可以挑選。

在此輸入圖像描述

NUnit附帶一個應用程序,應用程序可以啟動您想要的測試。 它非常有用,您不必編寫代碼來運行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM