-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Refactoring Suite, Parameterized and class runners to allow reuse in custom Runners #1348
base: main
Are you sure you want to change the base?
Refactoring Suite, Parameterized and class runners to allow reuse in custom Runners #1348
Conversation
RunnerFactory class to top-level Parameterized class to be accessible from other classes.
Could you please remove all the unnecessary reformatting? It makes it hard to review. On first glance, the methods being added to allParameters() could be a new non-static method in TestClass I don't understand why you need the changes to |
@kcooney How should I remove the formatting? Sorry, but Eclipse always formats the whole file and it's not my fault that this file wasn't formatted accordingly before :-/ |
Tell Eclipse to not format files on save (or, if possible to only reformat changes lines). I realize the files might not follow the current formater settings, but reviewing code that is reformatted in the same pull is painful |
Maybe we should have another PR to format all files under |
Regarding your feedback, @kcooney :
Would it appeal more to you, if I move all those annotation-related methods to a single (or multiple?) helper class? Its constructor could be initialised with an instance of |
I personally prefer that we don't do a pass of reformatting all the files, because it creates conflicts for anyone with an open pull. Perhaps @marcphilipp feels differently. In any case, I'll try to continue the discussion, but it would be much easier without so many extraneous diffs. Addressing your bullets in order:
|
*/ | ||
public static Statement withBeforeClasses(Statement statement, TestClass testClass) { | ||
protected Statement withBeforeClasses(Statement statement) { |
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.
Curious why you want to call these directly vs. calling classBlock()
. If you cannot use classBlock()
then perhaps instead of making these three protected
we should extract one protected
method that calls all three so 1) your runner isn't hard-coding the order and 2) we can add more calls in the future (ex withClassFixtures()
). Perhaps call the new method withClassStatements()
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.
I like your proposal to introduce withClassStatements()
. I also had something like this in mind before, but didn't brought it to an end. I will incorporate it now.
I'd like to propose to leave withBeforeClasses(...)
(and the others) protected anyway. But the documentation should encourage to use withClassStatements()
.
I can't call ParentRunner.classBlock(...)
in my custom Runner
because between invoking the children and applying the class statements, I'd like to apply @TestRule
s. ParentRunner doesn't support these.
Statement statement = childrenInvoker(notifier);
List<TestRule> testRules = BlockJUnit4ClassRunner.getTestRules(testInstance, getTestClass());
statement = BlockJUnit4ClassRunner.withTestRules(testRules, getDescription(), statement);
statement = withClassStatements(statement);
return statement;
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.
@PeterWippermann I don't understand what you mean by "I can't call ParentRunner.classBlock(...) in my custom Runner because between invoking the children and applying the class statements, I'd like to apply @testrules". The method withClassRules()
applies all of the rules annotated with @ClassRule
. You shouldn't invoke rules annotated with TestRule
in ParentRunner
because there is no instance of the class.
@kcooney Please have a look on my updates :-) |
I'm sorry, but if you want me to spend more time on this you will need to remove all the extraneous reformatting |
Which files are you complaining about, @kcooney ?
I really recommend to format your code base once to meet your own code style. |
I reported #1350 to get the code style right. Afterwards comparing the code should be easy again. |
The problem with We've done passes in the past to reformat the code; it doesn't stick. It also causes merge conflicts for pending pulls. In any case, all the maintainers work on JUnit in our free time, so we have limited time to review pulls. Having a significant amount of reformatting that is unrelated to your functional changes makes it take longer to review the diffs. |
You were right! Still, I'm wondering why not all the files I touched got polluted like this. |
@kcooney Could you have another look on this please? |
@PeterWippermann I am sorry, but my new job has kept me quite busy. There are still a lot of extraneous diffs in this pull. That makes it take longer for me to re-review it when you ping the thread, and like all of the maintainers, I work on JUnit in my free time (which is very limited currently). |
Waiting for #1350 |
For the period before this PR can be merged, I set up a project that provides exactly this functionality and makes it available for reuse: https://github.com/PeterWippermann/parameterized-suite |
As discussed in #1338 I refactored some of runners to be able to reuse their functionality. This mainly included the conversion of private instance methods to public (static) class methods. When functionality was hidden in other methods I also introduced new methods (e.g. Parameterized.normalizeParameter(Object)).