The Standard Display Name Generator is the default Display Name Gernerotor of Junit 5.
package org.wesome.junit5;
public class AppleCalculator {
public int addApple(int apple1, int apple2) {
int apple = apple1 + apple2;
return apple;
}
}
package org.wesome.junit5;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.DisplayNameGenerator.Standard;
@DisplayNameGeneration(Standard.class)
class Apple_Calculator_Test {
@Test
void add_Apple() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(2, appleCalculator.addApple(1, 1), "1 apple + 1 apple is 2 apple");
}
@Nested
class Apple_Calculator_Nested_Test {
@Test
void add_Apple() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(4, appleCalculator.addApple(2, 2), "2 apple + 2 apple is 4 apple");
}
}
}
plugins {
id 'java'
}
group 'org.wesome'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}
Standard Display Name Generator Configuration Parameter
Standard Display Name Generator can be configured as Configuration Parameter in src/test/resources/junit-platform.properties
file.
package org.wesome.junit5;
public class AppleCalculator {
public int addApple(int apple1, int apple2) {
int apple = apple1 + apple2;
return apple;
}
}
package org.wesome.junit5;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class Apple_Calculator_Test {
@Test
void add_Apple() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(2, appleCalculator.addApple(1, 1), "1 apple + 1 apple is 2 apple");
}
@Nested
class Apple_Calculator_Nested_Test {
@Test
void add_Apple() {
AppleCalculator appleCalculator = new AppleCalculator();
assertEquals(4, appleCalculator.addApple(2, 2), "2 apple + 2 apple is 4 apple");
}
}
}
junit.jupiter.displayname.generator.default=org.junit.jupiter.api.DisplayNameGenerator$Standard
plugins {
id 'java'
}
group 'org.wesome'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}