Skip to content

Commit

Permalink
Display test names in a more user-friendly way
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <fbricon@gmail.com>
  • Loading branch information
fbricon committed Apr 22, 2020
1 parent 47fe693 commit e7873c9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
5 changes: 5 additions & 0 deletions org.eclipse.lemminx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lemminx.junit;

import java.lang.reflect.Method;

import org.junit.jupiter.api.DisplayNameGenerator;

public class CamelCaseDisplayNameGenerator extends DisplayNameGenerator.Standard {

public String generateDisplayNameForClass(Class<?> testClass) {
return splitCamelCase(super.generateDisplayNameForClass(testClass));
}

public String generateDisplayNameForNestedClass(Class<?> nestedClass) {
return splitCamelCase(super.generateDisplayNameForNestedClass(nestedClass));
}

public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
return splitCamelCase(testMethod.getName());
}

String splitCamelCase(String text) {
//See https://stackoverflow.com/a/15370765/753170
return text.replaceAll("([A-Z])([A-Z])([a-z])|([a-z])([A-Z])", "$1$4 $2$3$5");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.lemminx.junit;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

// @formatter:off
public class CamelCaseDisplayNameGeneratorTest {

private CamelCaseDisplayNameGenerator nameGenerator;

@BeforeEach
public void setup() {
nameGenerator = new CamelCaseDisplayNameGenerator();
}

@Test
public void generateDisplayNameForClass() {
assertEquals("Camel Case Display Name Generator", nameGenerator.generateDisplayNameForClass(nameGenerator.getClass()));
}

@ParameterizedTest(name = "{index} => text={0}")
@CsvSource({ "ABCD, ABCD",
"AbCd, Ab Cd",
"abCd, ab Cd",
"aBCd, a BCd",
"a BC d, a BC d" })
public void splitCamelCase(String text, String expectedResult) {
assertEquals(expectedResult, nameGenerator.splitCamelCase(text));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.displayname.generator.default = org.eclipse.lemminx.junit.CamelCaseDisplayNameGenerator
35 changes: 30 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lsp4j.version>0.9.0</lsp4j.version>
<junit.version>5.6.1</junit.version>
</properties>
<url>https://github.com/eclipse/lemminx</url>
<licenses>
Expand All @@ -21,8 +22,8 @@
<connection>scm:git:git@github.com:eclipse/lemminx.git</connection>
<developerConnection>scm:git:git@github.com:eclipse/lemminx.git</developerConnection>
<url>https://github.com/eclipse/lemminx</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>
<modules>
<module>org.eclipse.lemminx</module>
</modules>
Expand Down Expand Up @@ -57,13 +58,19 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.1</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.1</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -88,9 +95,27 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<version>3.0.0-M4</version>
<configuration>
<runOrder>random</runOrder>
<statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<disable>false</disable>
<usePhrasedFileName>false</usePhrasedFileName>
<usePhrasedTestSuiteClassName>false</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>false</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
<consoleOutputReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
<disable>false</disable>
<encoding>UTF-8</encoding>
<usePhrasedFileName>false</usePhrasedFileName>
</consoleOutputReporter>
<statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
<disable>false</disable>
<usePhrasedFileName>false</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<usePhrasedClassNameInTestCaseSummary>false</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit e7873c9

Please sign in to comment.