I have an NUnit project creating a Console Application for running tests. The entry point looks like this:
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();
}
}
What can I pass in as an argument if I wanted to run this one test ONLY:
[TestFixture]
public class EmailNotificationTest
{
[Test]
public void MailerDefaultTest()
{
Assert.IsTrue(false);
}
}
Clearly this is supported, and just as clearly I have no idea how to do it.
UPDATE
It looks like with v3+, this is possible with the --test
option, per the documentation .
The latest version (NUnit 3) allows to debug tests and also to specify test(s) for execution.
Debug
The --debug
option launches debugger to debug tests, for example:
nunit3-console.exe "C:\path\to\the\tests.dll" --debug
Filter tests
Now you have a number of different ways to select test(s) to run. The first option is --test=NAMES
. Combining this option and --debug
you can easily debug only one test, for example:
nunit3-console.exe "C:\path\to\the\tests.dll" --debug --test="EmailNotificationTest.MailerDeSecondTest"
Don't forget about the namespace if the class has it.
Using --testlist=PATH
option you can run all tests specified in a file, for example:
nunit3-console.exe "C:\path\to\the\tests.dll" --debug --testlist="testnames.txt"
There is also --where=EXPRESSION
option indicating what tests will be run. This option is intended to extend or replace the earlier --test
, --include
and --exclude
options. Please check the official documentation if you want to know more about this option.
You can mark your test with [Category("RunOnlyThis")]
attribute, and then tell NUnit to run tests only matching this specific category:
/include:RunOnlyThis
is the attribute you need to add to console runner arguments. More here .
You can use /run switch of NUnit console to specify the test that you want to run.
Like this:
/run:namespace.classname.functionName
Eg
nunit-console.exe "C:\UnitTests.dll" /run:UnitTests.EmailNotificationTest.MailerDefaultTest
As @Toto said, use the NUnit Gui , you can pick and choose.
An application comes with NUnit, and the application can launch the test you want. It's really useful, and you don't have to write code to run test.
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.