Tutorials  /  JavaScript

JUnit Display Name - @DisplayName

Ccentron Redaktion · March 2024 ·2 min read ·JavaScript, Tutorial

Contents

  1. JUnit Display Name Example
  2. JUnit Display Name - Summary

JUnit @DisplayName annotation is used to provide a custom name for the test class and test methods. We can use spaces, special characters, and even emojis in the display name.

JUnit Display Name Example

By default, JUnit reporting prints the class name and method name in the IDE test report. We can use @DisplayName to specify a custom name that is easy to read and provide information about the test class and method. Let’s see some examples of JUnit Jupiter @DisplayName annotation.

For Test Class

Code
@DisplayName("MyTestClass")
public class DisplayNameTest {
}

For Methods

Code
@Test
@DisplayName("Example Test Method with No Business Logic")
void test() {
	assertTrue(3 > 0);
}

With Emojis

Code
@Test
@DisplayName("MyTestMethod ☺")
void test1(TestInfo testInfo) {
	assertEquals("MyTestMethod ☺", testInfo.getDisplayName());
}

Notice that we can get the Test method display name in the method by injecting TestInfo to the method argument.

VM

Matching infrastructure at centron

Node applications need somewhere to run: ccloud³ VMs with full root access from €4.04 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server →

JUnit Display Name - Summary

JUnit Jupiter @DisplayName annotation doesn’t provide any testing benefits. However, it can be used to provide information about the test methods that show in reporting and can be understood easily by any non-technical user too.

Claim €200 credit

Test your setup on ccloud³

Sign up for ccloud³ and receive €200 starting credit for your project.

centron Redaktion Technical editorial team

The centron editorial team writes guides from day-to-day operations: tested on our own platform, run in our data centre in Hallstadt near Bamberg.

Category JavaScript
Share
Still have questions?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

Was this tutorial helpful?

Your answer is stored anonymously and helps us improve our tutorials.

Comments

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Get started for free

Sign up and receive €200 credit at centron within your first 60 days.

This promotional offer applies to new accounts only. Available exclusively to businesses.