Hamcrest Matcher doesn't work in chrome_test_java tests |
||||
Issue descriptionI tried to write a test using org.hamcrest.matchers.containsString in an instrumentation test that is part of chrome_test_java. The test works fine on my local device but fails on the trybot. It would be great if these matchers could be used in instrumentation tests. Does someone know what could cause this issue and how it could be fixed? I also don't understand why StringContains shows up in package org.a.a.a.b? Here is a sample cl that shows the problem: http://crrev.com/2757583002 In order to use hamcrest I had to add "//third_party/hamcrest:hamcrest_java" and "//third_party/junit" as dependencies to chrome_test_java. Stacktrace: org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferencesTest#testHamcrestContains (run #1): java.lang.Error: Cannot determine correct type for matchesSafely() method. at org.a.h.<init>(TypeSafeMatcher.java:1049) at org.a.h.<init>(TypeSafeMatcher.java:22) at org.a.a.b.<init>(SubstringMatcher.java:13) at org.a.a.a.<init>(StringContains.java:13) at org.a.a.a.b(StringContains.java:39) at org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferencesTest.testHamcrestContains(ClearBrowsingDataPreferencesTest.java:1502) (https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Ftryserver.chromium.android%2Flinux_android_rel_ng%2F251537%2F%2B%2Frecipes%2Fsteps%2Fchrome_public_test_apk__with_patch__on_Android%2F0%2Flogs%2Forg.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferencesTest_testHamcrestContains%2F0)
,
Mar 16 2017
,
Mar 16 2017
When you're successfully running this locally, are you using a debug build or a release build? Any other potentially relevant gn args?
,
Mar 16 2017
This is my config: target_os = "android" target_cpu = "arm" is_debug = true use_goma = true is_component_build = true remove_webcore_debug_symbols = true is_clang = true symbol_level = 1 # Faster build with fewer symbols. -g1 rather than -g2 enable_incremental_javac = true # Much faster; experimental disable_incremental_isolated_processes=true I run it with: out/Android/bin/run_chrome_public_test_apk_incremental -f "*ClearBrowsingDataPreferencesTest*Contains*" I just created an out directory with the same config but with is_debug=false and without incremental_javac and the test passes there too.
,
Mar 21 2017
Yoland, can you look at this when you get a chance?
,
Mar 21 2017
I think it's related to proguard and how hamcrest reflectively find methods/classes (https://github.com/hamcrest/JavaHamcrest/blob/master/hamcrest-core/src/main/java/org/hamcrest/internal/ReflectiveTypeFinder.java). A workaround in this case, in which matchSafely can't be reflectively found, might be just add proguard rule to keep all hamcrest classes. I will try it out later today
,
Mar 22 2017
As expected, because hamcrest uses reflection on some of its own methods (to make sure generics are correct for the matchers?), proguard obfuscation would cause it to fail. Added this CL to fix the issue https://codereview.chromium.org/2764003003 This CL should verify that it's working: https://codereview.chromium.org/2770533002/#ps1
,
Mar 22 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/960eba52b467435abe56bf27078796c423754ce4 commit 960eba52b467435abe56bf27078796c423754ce4 Author: yolandyan <yolandyan@chromium.org> Date: Wed Mar 22 07:18:13 2017 Do not obfuscate hamcrest classes Do not obfuscate hamcrest classes since there are matchers in hamcrest that uses reflection on its own methods, and would result in error when proguard obfuscate them BUG= 702152 Review-Url: https://codereview.chromium.org/2764003003 Cr-Commit-Position: refs/heads/master@{#458660} [modify] https://crrev.com/960eba52b467435abe56bf27078796c423754ce4/third_party/hamcrest/BUILD.gn [add] https://crrev.com/960eba52b467435abe56bf27078796c423754ce4/third_party/hamcrest/proguard.flags
,
Mar 22 2017
|
||||
►
Sign in to add a comment |
||||
Comment 1 by dullweber@chromium.org
, Mar 16 2017