-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add test filter mechanism #196
base: main
Are you sure you want to change the base?
Conversation
@fmck3516 what is the best way to get a list of all the tests that we want to skip? |
project.getExtensions().getByType(BaseExtension.class).testOptions(testOptions -> { | ||
testOptions.unitTests(unitTestOptions -> { | ||
unitTestOptions.all(test -> { | ||
// todo: get all the tests that we can exclude and pass it to `test.exclude()`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmck3516 I want to pass that list here:
testToSkipList.forEach(test::exclude)
I really like the idea to enable Skippy per default like that. For JUnit 5, this could be some syntactic sugar on top of Automatic Extension Registration I still have no idea how to do that for JUnit 4 w/o manipulating the bytecode of the tests. |
Shooting from the hip: I think some kind of predicate that the user can provide. The implementation (e.g., match against a list or matching via regular expressions) could be left as exercise to the user. |
I did a small investigation, I am not sure if I am on the right way so let me know if I am missing something :) As far as I understood here we are taking the decision to skip the test or not: Looks like it is easy to change/overload the first parameter of |
Have you seen:
I already anticipated that users will want to have fine-grained control over when to apply Skippy. Would you be able to utilize this extension point? I'm open for other proposals if that's not a good fit. Just wanted to make sure it's on your radar. |
I've added a regression tests for the duplicate class names across output folders scenario: https://github.com/skippy-io/skippy-regression-suite/tree/main/test-projects/junit5-duplicate-class-names
If you reason on the class name alone, you won't be able to map the test that is being executed to a test in |
I'm thinking something like https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html that is used by Gradle to filter tests:
Possilbe Skippy equivalent:
Optionally with support for output folders:
The SkippyPlugin can pass the configuration as JVM parameter to the tests:
Reason I'm thinking about JVM parameter: This would allow me to use the same approach for the Gradle (Java) & Maven plugin. |
That would definitely be 1000x more user friendly than registration of a custom |
I just tested, it is possible to obtain the same behavior without involving the AGP: project.getTasks().withType(Test.class).all(test -> {
testToSkipList.forEach(test::exclude)
}); So it may work on android and jvm.
I am not sure I understood what is the benefit. |
In the above, don't you disable the tests alltogether? Instead of disabling Skippy? |
sorry for confusion, I will remove that wildcard. The idea is that we can use the same logic for jvm and android, we just depend on gradle api, not on AGP api |
Cool. Can you sketch how Skippy would consume the info that you pass to the test task? That would clear up things for me quite a bit. |
In my head the consumer is the task, not skippy. The data that I want to pass to the task must come from skippy. So skippy has an algorithm to calculate which test must be skipped, I want to pass that list to the test task. So the only thing I need and I don't know how to obtain is the list of tests that we want to skip. As far as I understood right now skippy is doing all the calculations lazily, when the test is executed. I need to have everything already calculated before running the tests, to be able to filter the tests. |
Ah, I was just about to stop the comment ping-pong and suggest a quick call. I think I understand what you try to do. I will whip something up to fill in the missing pieces. |
Now that I understand what you try to do: That's a really interesting approach to overcome the fact that JUnit 4 doesn't have a counterpart to JUnit 5's automatic extension registration. |
K, I've sketched how to generate exclusions based on Skippy's predictions: https://github.com/skippy-io/skippy/pull/199/files I didn't touch the 1st build:
2nd build:
Unfortunately, this only solves the issue partially: The test cases still need to use the Skippy rule. Otherwise the first build will create a The above replaces the SkipOrExecuteRule. But there is still the CoverageFileRule. Do you see a way to call the |
I played around with Gradle's AbstractTestTask#addTestListener - without much success since the listener and the tests are executed in separate JVMs. That's why I can't use the |
The test listener is triggered when the tests are running. It is too late for us, we want to know the skippable items before we are running the tests. Filtering is applied before running(I am not 100% sure yet tbh ;) ), that means we must have the list before. |
The |
The listener is not working in all the cases? Or only under some specific circumstances? |
What you suggested takes care of the functionality that is provided by the And I still have not figured out how to generate coverage for JUnit 4 w/o the need for a |
It doesn't work at all, since it is executed in a different JVM. Hence, it does not see any coverage data from the tests. |
Can you please share some code because I don't really understand how coverage can help us with test filter mechanism? |
Sure - I will whip up a sample project to demonstrate the issue I'm talking about some time in the evening. |
Build
Checkout
Go to
Next, check the content of
The key here is the empty
Next, add the Skippy rule to
Run the tests again:
Check the content of
The
What I try to demonstrate here: The |
Add a possibility to run all the tests by default using skippy without editing the tests(add rules to junit4 or annotations to junit5).
We can hide this feature behind a feature flag:
build.gradle
#189