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

TestsFilter arguments not working on NUnit Tests #13

Open
kamilchodola opened this issue Jan 23, 2019 · 10 comments
Open

TestsFilter arguments not working on NUnit Tests #13

kamilchodola opened this issue Jan 23, 2019 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@kamilchodola
Copy link

kamilchodola commented Jan 23, 2019

Hello,

In my tests i wanted to use argument --testsFilter to pick tests from 2 categories eg.:
--testsFilter="test.Categories.Contains(\"Cat1\") AND test.Categories.Contains(\"Cat2\")".

When I use an argument like this, my testSuite is not filtered to tests with these two categories. It starts to run all tests from an assembly. I must use Test Selection Language from NUnit passed in --nativeRunnerArguments argument:
--where cat==Cat1&&cat==Cat2
But here is a small problem too, because I need to write it like above, without whitespaces and quotation marks. In the example, on the NUnit page, there is an example like below:
nunit3-console mytest.dll --where "cat == Urgent || Priority == High"

If I use whitespaces without quotation marks it starts filtering to bad tests.

@angelovstanton
Copy link
Member

Mm, you need to use the filter for dotnet vstest since underneath we use it to run the tests.

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-vstest?tabs=netcore21

@angelovstanton
Copy link
Member

Can you try the format described in their official documentation and tell me whether it worked?

@angelovstanton angelovstanton self-assigned this Jan 23, 2019
@angelovstanton angelovstanton added the bug Something isn't working label Jan 23, 2019
@kamilchodola
Copy link
Author

Format from VStest properly filtered tests in my case. But I have NUnit framework, so it not started. I can only verify by sum od tests printed in the console.

@angelovstanton
Copy link
Member

If your projects are on .NET Core or Standard and you install needed nuget packages, you will be able to run not only MSTest tests with dotnet vstest but NUnit as well.

@kamilchodola
Copy link
Author

OK, I probably know why it doesn't work. I have a category attached to the whole fixture, not to each test. In that case, Meissa returns 0 categories on filtering. Is that correct? I know in the code it's made for a reason, but I think when we give a category for the whole fixture, each test in this fixture is in this category. When we are using Test Selection Language in NUnit using --where cat=Cat1 we choose all tests from fixtures with category Cat1 and all tests with category Cat1.

@angelovstanton
Copy link
Member

If you have 10 minutes for an experiment I can guide you how to debug the plugin and figure out what exactly is the problem. You will just need to create a console app, reference the nunit plugin and create instance of NativeTestsRunnerTestCasesPluginService class and call the method ExtractAllTestCasesFromTestLibrary supplying the path to your dll. Run it in debug and see what is happening.

@kamilchodola
Copy link
Author

kamilchodola commented Jan 28, 2019

I am debugging it already from the source code of Meissa ;) I attach to a dotnet.exe process and make few breakpoints. I made an experiment just 5 minutes ago. I have a class like a below

[TestFixture]
[Category("Cat1")]
public class TestClass
{
  [Test]
  public void Test1{}
  [Test]
  public void Test2{}
}

When i start Meissa Runner with --testsFilter="test.Categories.Contains("Cat1"), method FilterCases return 0 tests.

After that, I change the implementation of a fixture to:

[TestFixture]
public class TestClass
{
  [Test][Category("Cat1")]
  public void Test1{}
  [Test][Category("Cat1")]
  public void Test2{}
}

this time it works good, retrive both tests and split them into agents correctly.

@angelovstanton
Copy link
Member

If I remember correctly we get the attributes only of the test methods, this is why

@kamilchodola
Copy link
Author

Yes, I see it on the code. But is it correct? I made a workaround by passing category for each test case (luckily it was only 10 tests cases in a situation I needed).

@angelovstanton
Copy link
Member

To be honest not sure. Maybe it should take the types as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants