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

Including regexes to handle more JUnit 5 parameterized tests #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class Utils {
private static final Pattern junit5BasicPattern = Pattern.compile(junit5BasicRegex);
private static final String junit5NestedRegex = "\\[nested-class:([\\w.]+)\\]";
private static final Pattern junit5NestedPattern = Pattern.compile(junit5NestedRegex);
private static final String junit5ParameterizedRegex = "\\[class:([\\w.]+).*\\[test-template:([\\w().]+).*\\[test-template-invocation:#([\\w.]+)";
private static final Pattern junit5ParameterizedPattern = Pattern.compile(junit5ParameterizedRegex);
private static final String junit4Regex = "\\[test:(\\w+)\\(([\\w.]+)\\)";
private static final Pattern junit4Pattern = Pattern.compile(junit4Regex);

Expand All @@ -18,6 +20,10 @@ public class Utils {
* uniqueId: [engine:junit-jupiter]/[class:com.luojl.demo.JUnit5DemoTest]/[method:TestC()]
* full qualified name: com.luojl.demo.JUnit5DemoTest#TestC()
*
* For JUnit 5 parameterized test:
* uniqueId: [engine:junit-jupiter]/[class:com.luojl.demo.JUnit5DemoTest]/[method:TestC()][\[1\]]
* full qualified name: com.luojl.demo.JUnit5DemoTest#TestC()[1]
*
* For JUnit 5 nested test:
* uniqueId: [engine:junit-jupiter]/[class:com.luojl.demo.InheritedTest]/[nested-class:NestedTest]/[method:NestedTestB()]
* fully qualified name: com.luojl.demo.InheritedTest$NestedTest#NestedTestB()
Expand All @@ -43,8 +49,23 @@ public static String toFullyQualifiedName(String identifierUniqueId) {

sb.append("#");
sb.append(matcher.group(2)); // method

return sb.toString();
}
// try JUnit 5 parameterized pattern
matcher = junit5ParameterizedPattern.matcher(identifierUniqueId);
if (matcher.find()) {
StringBuilder sb = new StringBuilder();
sb.append(matcher.group(1)); // com.package.ClassName
sb.append("#");
sb.append(matcher.group(2)); // method
sb.append("[");
sb.append(matcher.group(3)); // parameter
sb.append("[");
sb.append("]");
return sb.toString();
}

// fall back to JUnit 4
matcher = junit4Pattern.matcher(identifierUniqueId);
if (matcher.find()) {
Expand Down
Loading