Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display test names in a more user-friendly way #647

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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