From 20852491bf4ce47e90fc56887213e66a9b83a039 Mon Sep 17 00:00:00 2001 From: August Shi Date: Fri, 8 Apr 2022 17:31:12 +0000 Subject: [PATCH] Some more regexes to deal with special JUnit 5 test patterns such as for parameterized tests --- .../cs/testrunner/execution/Utils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/testrunner-running/src/main/scala/edu/illinois/cs/testrunner/execution/Utils.java b/testrunner-running/src/main/scala/edu/illinois/cs/testrunner/execution/Utils.java index a039136..09950fe 100644 --- a/testrunner-running/src/main/scala/edu/illinois/cs/testrunner/execution/Utils.java +++ b/testrunner-running/src/main/scala/edu/illinois/cs/testrunner/execution/Utils.java @@ -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); @@ -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() @@ -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()) {