‘name’ attribute of ParameterizedTest annotations provides support for placeholders to customize the display name.
Below table summarizes placeholders supported in custom display names.
| 
   Placeholder  | 
  
   Display Name  | 
 
| 
   {displayName}  | 
  
   the display name of the method  | 
 
| 
   {index}  | 
  
   the current invocation index (1-based)  | 
 
| 
   {arguments}  | 
  
   the complete, comma-separated arguments list  | 
 
| 
   {argumentsWithNames}  | 
  
   the complete, comma-separated arguments list with parameter names  | 
 
| 
   {0}, {1}, …  | 
  
   an individual argument  | 
 
Find the below working application.
ParameterizedTestCustomDisplayName.java
package com.sample.app;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class ParameterizedTestCustomDisplayName {
	@DisplayName("demoTest")
	@ParameterizedTest(name = "{index} ==> the Capital of ''{0}'' is {1}")
	@CsvSource({ "India, New Delhi", "AFGHANISTAN, KABUL", "'CENTRAL AFRICAN REPUBLIC', BANGUI" })
	void testWithCustomDisplayNames(String country, String capital) {
		
		
	}
}
Run above test class, you can observe that the display names are reflected in junit window.
  

No comments:
Post a Comment