Indicative Sentences Display Name Generator creates the complete Display Name sentence by concatenating the name of the test class and the test case method.
Simple Display Name Generator extends Standard Display Name Generator. It removes the trailing parentheses of methods with no parameters.
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.IndicativeSentences;
@DisplayNameGeneration(IndicativeSentences.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()
}
Indicative Sentences Display Name Generator Configuration Parameter
Indicative Sentences 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$IndicativeSentences
plugins {
id 'java'
}
group 'org.wesome'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
test {
useJUnitPlatform()
}