Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrade from version 3.14.0 to 4.* running multiple test categories in parentheses separated with 'OR' stopped working #4651

Open
cjohnsson opened this issue Mar 4, 2024 · 3 comments
Labels

Comments

@cjohnsson
Copy link

cjohnsson commented Mar 4, 2024

Versions of lib
.NET 6, NUnit 4.1.0 with NUnit3TestAdapter 4.5.0 and Microsoft.NET.Test.Sdk 17.9.0.

Command to execute tests
dotnet test "testingnunit.dll" --verbosity d --filter "(TestCategory=TestsA&TestCategory!=TestsB)|(TestCategory=TestsC)"

How to reproduce

  1. Create a project called testingnunit with the provided example class in it. Build the project.
  2. Run the test command, no tests will be found when running with NUnit version 4.0.0 or later.
    Output is "No test matches the given testcase filter".
    image
  3. If you downgrade NUnit to version 3.14.0 and run the test command it finds the tests. TestInA and TestInC are exectued, TestInB is excluded as expected.
    image

How to mitigate the problem when running with NUnit 4.1.0
Run dotnet test for each filter within parentheses.
First run dotnet test "testingnunit.dll" --verbosity d --filter "(TestCategory=TestsA&TestCategory!=TestsB)", and then run dotnet test "testingnunit.dll" --verbosity d --filter "(TestCategory=TestsC)"

Code example

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
      <PackageReference Include="NUnit" Version="4.1.0" />
      <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
    </ItemGroup>
</Project>
using NUnit.Framework;

namespace TestingNunit;

[TestFixture, Category("TestsA")]
public class TestsA
{
    [Test]
    public void TestInA()
    {
        Assert.Pass();
    }
}

[TestFixture, Category("TestsB")]
public class TestsB
{
    [Test]
    public void TestInB()
    {
        Assert.Fail();
    }
}

[TestFixture, Category("TestsC")]
public class TestsC
{
    [Test]
    public void TestInC()
    {
        Assert.Pass();
    }
}
@cjohnsson
Copy link
Author

cjohnsson commented Mar 4, 2024

The above is a problem if you have a project with many test categories and want to create complex filters.

In my case I want to execute all tests that are not ignored for a module, except the ones that are categorized as slow/obtrusive, and I also want to include not ignored cross-module "smoketests".

My test filter that works in NUnit 3.14.0 but fails to find any tests in NUnit 4.1.0
(TestCategory=MyModule&TestCategory!=Obtrusive&TestCategory!=Slow&TestCategory!=Ignored)|(TestCategory=Smoketest&TestCategory!=Ignored)

@OsirisTerje
Copy link
Member

Thanks! So with 3.14.0 and adapter 4.5.0 it works, but with 4.1.0 and adapter 4.5.0 it doesn't work?

@cjohnsson
Copy link
Author

Thanks! So with 3.14.0 and adapter 4.5.0 it works, but with 4.1.0 and adapter 4.5.0 it doesn't work?

Exactly.

@cjohnsson cjohnsson changed the title After upgrade from version 3.14.0 to 4.* separating multiple testcategories inside parentheses with 'OR' stopped working After upgrade from version 3.14.0 to 4.* running multiple test categories in parentheses separated with 'OR' stopped working Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants