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

Inconsistent filtering between ParentRunner.getFilteredChildren() and getDescription() #122

Open
paulduffin opened this issue May 25, 2017 · 1 comment
Labels

Comments

@paulduffin
Copy link

Background: I am working on Android and trying to use JUnitParams with the Android Test Support Library, specifically the AndroidJUnitRunner class which runs classes on the device. During that work I discovered that JUnitParams applies filtering inconsistently depending on whether it is for the getFilteredChildren() method or the getDescription() method.

In getFilteredChildren() the filter is applied to a flat list of FrameworkMethod instances, where each parameterized method has been expanded into N FrameworkMethod (where N is the number of parameter sets).

In getDescription() the filter is applied to a flat list of FrameworkMethod instances where each parameterized method is represented by a single FrameworkMethod. After the filtering has been applied then each parameterized FrameworkMethod is expanded to N Description objects.

e.g. in getDescription(), before filtering:

  • method1
  • method2
    After applying filter
  • method1
    After instantiating
  • method1
  • method1[0]
  • method1[1]
  • method1[2]
  • method1[3]
  • method1[4]

in getFilteredChildren(), after instantiation, before filtering:

  • method1[0]
  • method1[1]
  • method1[2]
  • method1[3]
  • method1[4]
  • method2[0]
  • method2[1]
  • method2[2]
    After applying filter
  • method1[0]
  • method1[2]
  • method2[1]

The filter that is being applied is the sharding filter which basically decides if a test should run with the following test, where numShards is the number of devices you have available and shardIndex is the number of the shard on the current device.

    boolean shouldRun(Description description) {
        if (description.isTest()) return (description.hashCode() % numShards) == shardIndex;
        return true;
    }

I also discovered a number of other Filter related issues.

Applying multiple Filters consecutively does not work. They are applied correctly to getFilteredChildren() but only the last filter applied affects the Description.

Calling getDescription() and then applying a Filter does not change the Description.

I have an initial change that I have created with fixes this issue, it needs some work (I think I broke JUnitParams.flat system property) but it does show the basic approach I took.

paulduffin added a commit to paulduffin/JUnitParams that referenced this issue May 25, 2017
paulduffin added a commit to paulduffin/JUnitParams that referenced this issue May 26, 2017
@paulduffin
Copy link
Author

Any feedback on this?

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