question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sortWith() and orderWith() should respect @FixMethodOrder

See original GitHub issue

When you order a suite using Request.sortWith() all of the runners that implement Sortable (like BlockJUnit4ClassRunner) will reorder their methods using the passed-in Comparator, even if the ordering was specified with @FixMethodOrder. The same holds true for Request.orderWith(). JUnit should instead not reorder methods for classes annotated with @FixMethodOrder

Background:

Someone at my company was trying to implement code to shuffle method orders to catch tests that produced different pass/fail results based on ordering (these shuffling tests are useful, for instance, if you want to ensure that you could always add @Ignore to a broken test without causing otherwise-passing tests to start failing). We have a very large code base, and some tests are annotated with @FixMethodOrder because we know that they only pass if run in a specific order. We have enough of these that it will take a significant amount of time to fix them, especially for parts of the code where the original authors have left the company.

We had to write custom shuffling code, because the code in JUnit for ordering did not respect @FixMethodOrder. In some cases, our customized shuffling code has to bail out with a “Shuffling not supported for this suite” error message.

Can we please have ParentRunner.sort(Sorter) and ParentRunner.order(Orderer) do nothing if the Description indicates that the class was annotated with @FixMethodOrder?

I do realize that this would be a change in behavior from previous versions of JUnit. I don’t think the change I’m proposing would cause tests to fail. The only way that could happen is if there is some code outside of JUnit that specifically orders the suite in an order, but if projects run into this problem when trying to migrate to 4.13, the easy work-around would be to remove the @FixMethodOrder annotation.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcphilippcommented, Nov 18, 2019

Yes, I think so unless there’s a really good reason.

Since orderWith() is new, I think we should make the change now and postpone 4.13.

0reactions
kcooneycommented, Nov 19, 2019

@marcphilipp while Request,orderWith() and @OrderWith are new, Request.sortWith() is not. I think it might be odd to have the orderWith() respect @FixMethodOrder but sortWith() not respect it. That being said, if we change the sorting code so sortWith() respects @FixMethodOrder we would likely need to see who might broken by the change, which would require a delay of the 4.13 release.

I’ll start looking into where we could apply the fixes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found