Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:59:02+00:00 2026-06-15T12:59:02+00:00

junit 4.11 comes with the @FixMethodOrder -annotation, which makes it possible to select a

  • 0

junit 4.11 comes with the @FixMethodOrder-annotation, which makes it possible to select a MethodSorter-implementation to order the junit tests. There are three default sorters, JVM, NAME_ASCENDING and DEFAULT.

Now, I would like to create my own MethodSorter. Can anyone help me with any pointers to how to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:59:04+00:00Added an answer on June 15, 2026 at 12:59 pm

    Short Answer

    This isn’t easy, and is discouraged, because JUnit doesn’t encourage dependent tests.

    Long Answer

    For more information, see extended discussion on SortMethodsWith allows the user to choose the order of execution of the methods within a test class.

    JUnit doesn’t encourage people to write tests which are dependent on other tests. @FixMethodOrder was introduced following a discussion on Sort test methods for predictability.

    The basic problem was that Java 7, when using reflection to find methods, doesn’t return them in a consistent order. With Java 6, it was pretty much guaranteed that they’d be returned in the order in which they appear in the source file. This is no longer the case.

    Some test classes have dependent tests (whether by design or by accident). Sort test methods for predictability at least guarantees that these tests will be executed in a consistent order. However, this ordering is based on the hashCode of the method, so the ordering is deterministic, but hard to predict. So if, you do have a problem with your ordering of tests, then it isn’t easy or obvious how to fix the ordering. You have to find a test method name with a higher/lower hashCode.

    @FixMethodOrder was introduced to allow the users to fix their ordering problem easily, simply by changing the name. But, for me at least, it’s seen as a temporary fix, until the broken tests can be fixed.

    Please note also that you can usually specify test execution order from surefire, and there are similar options in ant.

    For more information, I’ve just published a blog post on this very subject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Junit, I know there is a @beforeclass , @before annotation, do we have
Quick JUnit question. I'm running some unit tests that involve starting up the GUI
I'm writing JUnit tests for a service that creates and acts on an entity
I write JUnit tests for some Spring MVC Controllers. The initialization of the JUnit
Failing JUnit tests, not breaking my Ant script like I expect? My continuous integration
Is there a recommended way to integrate Hamcrest into the JUnit configuration in Eclipse?
Junit report does not generate report if there is assertion error Class to be
In JUnit tests, I need to test that a given object (not the reference,
I am configuring JUnit in Ant so that unit tests will be run on
I have a Junit test class with two tests in it. test 1 will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.