JUNIT Specifies the test execution order

Source: Internet
Author: User
Tags reflection
Original link: Test execution order
Original date: December 06, 2012
Translation Date: July 2, 2014
Translation staff: Anchor

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

By design principles, JUnit does not specify the order in which test method calls are performed.
So far, these methods are simply executed in the order returned by the reflection (reflection) API.
However, it is unwise to use the sort provided by the JVM by default, because the Java platform does not specify any regular order,
In fact, JDK 7 may return a random order.
Of course, there is no need to assume any sequence of execution between well-written test code, but sometimes it is better to have a predictable failure on some platforms than a random failure.

Starting with version 4.11, JUnit will default to a determined, but unpredictable, order (Methodsorters.default).
To change the order of the test execution, you only need to use the @FixMethodOrder annotation on the test class (Class) and specify an available Methodsorter:

@FixMethodOrder (METHODSORTERS.JVM): The order in which the execution of test methods is kept is returned by the JVM. The sequence of execution of each test may be different.

@FixMethodOrder (methodsorters.name_ascending) : Sorting according to the method name of the test method, according to the Dictionary sorting rule (ASC, from small to large, increment).


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.