Interface ClassOrderer

All Known Implementing Classes:
ClassOrderer.ClassName, ClassOrderer.DisplayName, ClassOrderer.OrderAnnotation, ClassOrderer.Random

@API(status=EXPERIMENTAL,
     since="5.8")
public interface ClassOrderer
ClassOrderer defines the API for ordering the top-level test classes, without considering nested test classes.

In this context, the term "test class" refers to any class containing methods annotated with @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, or @TestTemplate. @Nested test classes cannot be ordered by a ClassOrderer.

Built-in Implementations

JUnit Jupiter provides the following built-in ClassOrderer implementations.

Since:
5.8
See Also:
ClassOrdererContext, orderClasses(ClassOrdererContext)
  • Nested Class Summary

    Nested Classes
    Modifier and Type Interface Description
    static class  ClassOrderer.ClassName
    ClassOrderer that sorts classes alphanumerically based on their fully qualified names using String.compareTo(String).
    static class  ClassOrderer.DisplayName
    ClassOrderer that sorts classes alphanumerically based on their display names using String.compareTo(String)
    static class  ClassOrderer.OrderAnnotation
    ClassOrderer that sorts classes based on the @Order annotation.
    static class  ClassOrderer.Random
    ClassOrderer that orders classes pseudo-randomly.
  • Method Summary

    Modifier and Type Method Description
    void orderClasses​(ClassOrdererContext context)
    Order the classes encapsulated in the supplied ClassOrdererContext.
  • Method Details

    • orderClasses

      void orderClasses​(ClassOrdererContext context)
      Order the classes encapsulated in the supplied ClassOrdererContext.

      The classes to order or sort are made indirectly available via ClassOrdererContext.getClassDescriptors(). Since this method has a void return type, the list of class descriptors must be modified directly.

      For example, a simplified implementation of the ClassOrderer.Random ClassOrderer might look like the following.

       public void orderClasses(ClassOrdererContext context) {
           Collections.shuffle(context.getClassDescriptors());
       }
       
      Parameters:
      context - the ClassOrdererContext containing the class descriptors to order; never null