Search code examples
c#nunitnunit-console

C# - Nunit - nunit3-console not picking the mentioned class file in the where filter


While running an Nunit project with the .csproj extension through Nunit3-console, the two tests are correctly picked correctly.

nunit3-console.exe SeleniumCHash.csproj

But, when I try to filter out one of the tests by selecting the class file to be executed, the tests are not getting picked up.

nunit3-console.exe --where "class =~ 'SeleniumCHash: FirstTest'" SeleniumCHash.csproj

The following is my Class File.

namespace SeleniumCHash
{
    [TestFixture]
    public class FirstTest : TestBaseClass
    {
        [Test]
        public void LoginCheck()
        {
        }

    }
}

Solution

  • The syntax you are using suggests you have a class named "SeleniumCHash: FirstTest". Of course, that's impossible. So when no test is found, no tests are run.

    You don't provide your code, but I'm guessing it's something like

    namespace Some.Thing
    {
        public class SeleniumCHash
        {
            [Test]
            public void FirstTest() { ... }
            ...
        }
    }
    

    You could run FirstTest using any of the options

    --where "class == Some.Thing.SeleniumCHash && method == FirstTest"
    --test Some.Thing.SeleinumCHash.FirstTest
    --where "test == Some.Thing.SeleniumCHash.FirstTest"
    --where "test =~ FirstTest"
    

    The last one, of course, will only work if there are no other tests that match "FirstTest". If there are, then all of them will run.

    Note that class and method refer to the C# elements whereas test refers to the full name of the test, which usually contain those elements but which also may be modified by the user writing the test code.