-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display test names in a more user-friendly way
Signed-off-by: Fred Bricon <fbricon@gmail.com>
- Loading branch information
Showing
5 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...clipse.lemminx/src/test/java/org/eclipse/lemminx/junit/CamelCaseDisplayNameGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...se.lemminx/src/test/java/org/eclipse/lemminx/junit/CamelCaseDisplayNameGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
org.eclipse.lemminx/src/test/resources/junit-platform.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
junit.jupiter.displayname.generator.default = org.eclipse.lemminx.junit.CamelCaseDisplayNameGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters