JUNIT Specifies the test run order

Source: Internet
Author: User
Original link: Test execution order
Original date: December 06, 2012 This
Date: July 2, 2014
Translators: Anchor

Description: Junit4.11 version number and later support, it is recommended to upgrade to the latest version number.

In accordance with the design principle, JUnit does not specify the order in which the test method calls run.
For now, these methods simply run in the order returned by the reflection (reflection) API.
However, it is very unwise to use the default ordering provided by the JVM, since the Java platform is not specified in any regular order.
In fact, JDK 7 may return a random order.
Of course, there is no need to assume that no matter what the order of operation is between well-written test code, but sometimes a predictable failure on some platforms is better than a random failure.

Starting with the 4.11 version, JUnit will default to a deterministic, but not pre-measured order ( Methodsorters.default ).


To change the order of the test run, you only need to use @FixMethodOrder annotations on the test class (Class) and specify an available Methodsorter to:

@FixMethodOrder (METHODSORTERS.JVM) : preserves the order in which the test methods are run in the order that the JVM returns.

The order in which each test is run can be different.

@FixMethodOrder (methodsorters.name_ascending) : Sorts according to the method name of the test method, according to the dictionary control (ASC, small to large, increment).


JUNIT Specifies the test run order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.