7.1 @Suite annotation

And a few more frequently used annotations. Even if you don't use them, you will definitely see tests with them. Therefore, it is necessary to understand at least in general terms what is written there.

Tests can be combined into groups. There is a special annotation for this @Suite. Example:

@SuiteDisplayName("JUnit Platform Suite Demo")
class SuiteDemo {

In this case, the @Suite annotation is paired with other annotations.

  • SuiteDisplayName– sets the name of the test group in the log;
  • SelectPackages- sets the list of packages where to look for test classes;
  • IncludeClassNamePatterns– sets the pattern of test class names.

Why such difficulties? Well imagine that all tests of the project are executed, let's say, 50 hours. And to execute them after each commit is very expensive. In such a case, it is useful to create some separate test scripts and set up testing in a much more flexible way.

7.2 @Order annotation

Another common annotation is @TestMethodOrder. It allows you to specify the order in which test methods are called in the test class. It can be very useful when you know that method calls affect each other, but in a certain order, everything should work as it should. Used quite often.

First, you can set the methods to be called in alphabetical order :

public class AlphanumericOrderUnitTest {


Secondly, each method can have a special annotation with its ordinal number.

public class OrderAnnotationUnitTest {

    public void firstTest() {

    public void secondTest() {

Or even create a separate class that will specify the order in which the tests are called:

public class CustomOrderUnitTest {


//sort method names alphabetically, but ignoring case
public class CustomOrder implements MethodOrderer {
    public void orderMethods(MethodOrdererContext context) {
        (MethodDescriptor m1, MethodDescriptor m2)->

7.3 @DisplayName annotation

Finally, each test can be given a name. It can be convenient if there are a lot of tests and you create special scenarios (subsets) of tests. There is a special annotation for this @DisplayName.


@DisplayName("Friendly name for the test")
public class DisplayNameCustomTest {

    @DisplayName("Input Validation")
    void inputData() {

    @DisplayName("Checking critical situations")
    void criticalCases() {

As in the case of setting the order of tests, here you can create a special method that will generate the names of tests and test methods. Example:

class DisplayNameGeneratorUnitTest {

    void camelCaseName() {

    static class ReplaceCamelCase extends DisplayNameGenerator.Standard {
        public String generateDisplayNameForClass(Class testClass) {
            return super.generateDisplayNameForClass(testClass).toUpperCase();

See how easy it is :)