diff --git a/runner/android_junit_runner/java/androidx/test/internal/runner/RunnerArgs.java b/runner/android_junit_runner/java/androidx/test/internal/runner/RunnerArgs.java index d8a1092e0..4278ae145 100644 --- a/runner/android_junit_runner/java/androidx/test/internal/runner/RunnerArgs.java +++ b/runner/android_junit_runner/java/androidx/test/internal/runner/RunnerArgs.java @@ -91,9 +91,6 @@ public class RunnerArgs { private static final String CLASSPATH_SEPARATOR = ":"; // used to separate fully-qualified test case class name, and one of its methods private static final char METHOD_SEPARATOR = '#'; - // pattern used to identify java class names conforming to java naming conventions - private static final String CLASS_OR_METHOD_REGEX = - "^([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{Lu}_$][\\p{L}\\p{N}_$]*(#[\\p{L}_$][\\p{L}\\p{N}_$]*)?$"; public final boolean debug; public final boolean suiteAssignment; @@ -489,7 +486,13 @@ private BufferedReader openFile(Instrumentation instr, String filePath) throws I */ @VisibleForTesting static boolean isClassOrMethod(String line) { - return line.matches(CLASS_OR_METHOD_REGEX); + for (int i = 0; i < line.length(); i++) { + char c = line.charAt(i); + if (c == '#' || Character.isUpperCase(c)) { + return true; + } + } + return false; } /** diff --git a/runner/android_junit_runner/java/androidx/test/internal/runner/TestRequestBuilder.java b/runner/android_junit_runner/java/androidx/test/internal/runner/TestRequestBuilder.java index 9ffc324e1..ce0a89e1d 100644 --- a/runner/android_junit_runner/java/androidx/test/internal/runner/TestRequestBuilder.java +++ b/runner/android_junit_runner/java/androidx/test/internal/runner/TestRequestBuilder.java @@ -467,14 +467,16 @@ public boolean evaluateTest(Description description) { // Parameterized tests append "[#]" at the end of the method names. // For instance, "getFoo" would become "getFoo[0]". - methodName = stripParameterizedSuffix(methodName); - if (excludedMethods.contains(methodName)) { + // Method filters should be applied against both the parameterized name and root name + String rootMethodName = stripParameterizedSuffix(methodName); + if (excludedMethods.contains(methodName) || excludedMethods.contains(rootMethodName)) { return false; } // don't filter out descriptions with method name "initializationError", since // Junit will generate such descriptions in error cases, See ErrorReportingRunner return includedMethods.isEmpty() || includedMethods.contains(methodName) + || includedMethods.contains(rootMethodName) || methodName.equals("initializationError"); } diff --git a/runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java b/runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java index a2eab4c8d..169ef057a 100644 --- a/runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java +++ b/runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java @@ -391,26 +391,22 @@ public void isClassOrMethod() throws Exception { assertTrue(RunnerArgs.Builder.isClassOrMethod("Bar")); assertTrue(RunnerArgs.Builder.isClassOrMethod("Bar#method_$1")); assertTrue(RunnerArgs.Builder.isClassOrMethod("pkg.foo_1.foo$.Bar2#m")); + + // test parameterized name + assertTrue(RunnerArgs.Builder.isClassOrMethod("pkg.foo.Bar#method[0]")); } - /** - * Test static method isClassOrMethod in RunnerArgs.Builder with package names or invalid names - */ + /** Test static method isClassOrMethod in RunnerArgs.Builder */ @Test public void notClassOrMethod() throws Exception { // test valid package names assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg.foo.bar")); assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg")); assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg1.foo_2.bar$3")); + // invalid names should not register as class or method names assertFalse(RunnerArgs.Builder.isClassOrMethod("")); - assertFalse(RunnerArgs.Builder.isClassOrMethod(".pkg.foo.Bar")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg..foo.Bar")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg.foo.Bar.")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("2pkg.foo.Bar")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg.foo.Bar#method.1")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg.foo.Bar#method1%")); - assertFalse(RunnerArgs.Builder.isClassOrMethod("pkg.foo&.Bar#method1")); + assertFalse(RunnerArgs.Builder.isClassOrMethod("$^$%^")); } /** Test parsing bundle when test timeout is provided */