New issue
Advanced search Search tips

Issue 638318 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
Closed: Jun 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: Feature

Blocked on:
issue 707755
issue 709007

Blocking:
issue 807764



Sign in to add a comment

Make mockito work in instrumentation tests

Project Member Reported by jbudorick@chromium.org, Aug 16 2016

Issue description

Mockito currently only works in host-side java tests. Attempting to use it in an instrumentation test suite runs afoul of gn's supports_android checks. Addressing those results in a bunch of proguard errors when building release. (I haven't checked debug.)
 
Owner: mikec...@chromium.org
Any update on this thread?
hmmm, I should have updated the bug. I *think* I investigated this and found Mockito is not support on Android. Will check again sometime this week or next, verify this is the case and see if they updated/fixed it.
hmmm, I see this in the Mockito docs...

With Mockito version 2.6.1 we ship "native" Android support.

Seems like if we update Mockito then this might be possible. Previously, it appears you needed some dexmaker library to enable Mockito to be able to make .dex files on the fly.

So, yeah, this definitely should be possible.
Not sure if this is related but it says Mockito can be used on Android:
http://jeroenmols.com/blog/2017/01/17/mockitoandroid/
FYI I'm doing an initial attempt as it's blocking a project I'm working on. Will let you know if I succeed or not.
I got stuck in on thing:

https://chromium.googlesource.com/external/mockito/mockito.git/+/v2.7.20/src/main/java/org/mockito/internal/configuration/plugins/PluginLoader.java#83

Uses ClassLoader.getResources() to get the file in resources/mockto-extensions/MockMaker, which indicates the MockMaker class name used on Android:

https://chromium.googlesource.com/external/mockito/mockito.git/+/v2.7.20/subprojects/android/src/main/resources/mockito-extensions/org.mockito.plugins.MockMaker

However I'm unable to find a way to pack it into ChromePublicTest.apk. Any way to make it happen?
Blockedon: 707755
Owner: zqzh...@chromium.org
Status: Started (was: Available)
I got a prototype working. Taking this issue.
Blockedon: 709007
Cc: -mikec...@chromium.org
Owner: mikec...@chromium.org
I'm giving this out as I'm leaving Chrome soon and don't have enough time to finish this. Feel free to take over.

Also I was able to write my tests as junit tests so they no longer need to be instrumentation tests.

A working prototype is here:
CL: https://codereview.chromium.org/2790063006
Design doc: https://docs.google.com/a/google.com/document/d/1Vla1McDsX3AXDrvOcIqt4HemFcbWxozaoOaYIed4RUk/edit?usp=sharing
What is the status of this? If there is still interest in enabling mockito in instrumentation tests in Chromium then I can try to make and submit a patch for this.

We have several mockito+instrumentation tests in our downstream repo at Yandex, with Mockito 2.8.47. Having two versions of mockito (thrird_party/mockito being the other one) is troublesome, in particular, a test_support library cannot depend on mockito and be used in both junit and instrumentation tests.

Some notes about our experience with such tests:
- Tests are quite reliable, but some versions of Mockito were problematic - we had troubles in the past with 1.9.10 + dexmaker 1.4 and had to roll back to 1.9.5. Modern v2.8.47 seems good so far.
- Mocking on Android tends to be very slow. Our tests are executed on ARM emulator and typical simple test with mocks is ~ten times slower than similar one without mocks (20-30 seconds vs 2-5 seconds per test).
Cc: baxley@chromium.org yolandyan@chromium.org
Owner: ----
Status: Available (was: Started)
mikecase is no longer working on chromium. AFAIK he didn't make any progress beyond what zqzhang mentioned in #11. A patch would be more than welcome :)
Blocking: 807764
Owner: jbudorick@chromium.org
Status: Started (was: Available)
I've got this working locally, though in a bit different mechanism than #11. Will clean it up and upload a patch.
Cc: -yolandyan@chromium.org -baxley@chromium.org
Project Member

Comment 18 by bugdroid1@chromium.org, Jun 21 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/android_tools/+/3545ab5b9883087a54cb9e5337c32617cb2a443d

commit 3545ab5b9883087a54cb9e5337c32617cb2a443d
Author: John Budorick <jbudorick@chromium.org>
Date: Thu Jun 21 19:54:03 2018

Add version 25.0.2 of dx.jar to sdk/build-tools.

byte_buddy uses an older version of dx code when running on Android.

Bug:  638318 
Change-Id: I0a609850adb4173809b8d82e3390eebb4a3e62d6
Reviewed-on: https://chromium-review.googlesource.com/1083822
Reviewed-by: agrieve <agrieve@chromium.org>

[add] https://crrev.com/3545ab5b9883087a54cb9e5337c32617cb2a443d/sdk/build-tools/25.0.2/lib/dx.jar
[modify] https://crrev.com/3545ab5b9883087a54cb9e5337c32617cb2a443d/README.chromium

Project Member

Comment 19 by bugdroid1@chromium.org, Jun 22 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/6c26c230a2783279d251909cfcdc6b344401ebba

commit 6c26c230a2783279d251909cfcdc6b344401ebba
Author: John Budorick <jbudorick@chromium.org>
Date: Fri Jun 22 00:11:28 2018

Add support for using mockito in instrumentation tests.

Bug:  638318 
Change-Id: I1c3b1fbf83d70faa7c11f41de547e4ae82fbb211
Reviewed-on: https://chromium-review.googlesource.com/1103589
Commit-Queue: John Budorick <jbudorick@chromium.org>
Reviewed-by: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569464}
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/DEPS
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/build/android/gyp/javac.py
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/build/config/android/internal_rules.gni
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/build/secondary/third_party/android_tools/BUILD.gn
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/byte_buddy/BUILD.gn
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/byte_buddy/README.chromium
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/byte_buddy/cipd.yaml
[add] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/byte_buddy/proguard.flags
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/mockito/BUILD.gn
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/mockito/README.chromium
[add] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/mockito/proguard.flags
[modify] https://crrev.com/6c26c230a2783279d251909cfcdc6b344401ebba/third_party/objenesis/BUILD.gn

Need a fix for running on art due to https://github.com/mockito/mockito/issues/922.
Status: Fixed (was: Started)
Workaround for #20 landed in https://chromium.googlesource.com/chromium/src.git/+/bb76c8ae7cd2135463f77130066fce3b9963416b. Apparently, this got actually fixed on the android side w/ v1.0 of the support test runner, so once we upgrade to that, we can back out the workaround.

Sign in to add a comment