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.
Open a powershell window and run nunit3-console.exe with "--test" option set to reference the specific test you want to run (including namespace and class). and finally, provide the location of the assembly where the test can be found.
There is no facility in NUnit to order tests globally. Tests with an OrderAttribute argument are started before any tests without the attribute. Ordered tests are started in ascending order of the order argument. Among tests with the same order value or without the attribute, execution order is indeterminate.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With