From ab5f9f1d788a2cc59ae0e6b18d527a4f1acd5563 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 23 Mar 2017 15:33:37 +0000 Subject: Hard code text case name template for AndroidJUnitRunner and CTS AndroidJUnitRunner and CTS require test names to be a specific format. The default JUnitParams format is not suitable. This change forces it to one that is suitable and prevents it from being overridden using the @TestCaseName annotation. These are a sample of parameterized and unparameterized test names. The latter two are from a JUnitParamsRunner based test. libcore.java.net.FtpURLConnectionTest#testOutputUrl pass libcore.java.net.IDNTest#test_toUnicode_failures pass libcore.java.net.InetAddressTest#test_getByName_invalid[0] pass libcore.java.net.InetAddressTest#test_getByName_invalid[1] pass Bug: 36074730 Bug: 36541809 Test: run cts -m CtsLibcoreTestCases and check test names of parameterized tests, e.g. those from libcore.java.net.InetAddressTest Change-Id: Id9a8f8ce9affeb85fb2f410d11e764e99d7287b3 --- .../junitparams/naming/MacroSubstitutionNamingStrategy.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java b/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java index ce56847..1bdcafb 100644 --- a/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java +++ b/src/main/java/junitparams/naming/MacroSubstitutionNamingStrategy.java @@ -14,7 +14,9 @@ public class MacroSubstitutionNamingStrategy implements TestCaseNamingStrategy { private static final Pattern MACRO_SPLIT_PATTERN = Pattern.compile(String.format("(?=%s)|(?<=%s)", MACRO_PATTERN, MACRO_PATTERN)); private static final String MACRO_START = "{"; private static final String MACRO_END = "}"; - static final String DEFAULT_TEMPLATE = "[{index}] {params} ({method})"; + // Android-changed: CTS and AndroidJUnitRunner rely on specific format to test names, changing + // them will prevent CTS and AndroidJUnitRunner from working properly; see b/36541809 + static final String DEFAULT_TEMPLATE = "{method}[{index}]"; private TestMethod method; public MacroSubstitutionNamingStrategy(TestMethod testMethod) { @@ -37,7 +39,12 @@ public class MacroSubstitutionNamingStrategy implements TestCaseNamingStrategy { private String getTemplate(TestCaseName testCaseName) { if (testCaseName != null) { - return testCaseName.value(); + // Android-changed: CTS and AndroidJUnitRunner rely on specific format to test names, + // changing them will prevent CTS and AndroidJUnitRunner from working properly; + // see b/36541809 + throw new IllegalStateException( + "@TestCaseName not currently supported as it breaks running tests in CTS"); + // return testCaseName.value(); } return DEFAULT_TEMPLATE; -- cgit v1.2.3