Closed
Bug 1182193
Opened 10 years ago
Closed 9 years ago
Add unit test support to fennec.
Categories
(Firefox for Android Graveyard :: Android Sync, defect)
Firefox for Android Graveyard
Android Sync
Tracking
(firefox43 fixed, fennec+)
RESOLVED
FIXED
Firefox 43
People
(Reporter: nalexander, Assigned: vivek, Mentored)
References
Details
(Whiteboard: [lang=java][bad first bug])
Attachments
(5 files, 1 obsolete file)
40 bytes,
text/x-review-board-request
|
Details | |
40 bytes,
text/x-review-board-request
|
nalexander
:
review+
|
Details |
40 bytes,
text/x-review-board-request
|
nalexander
:
review+
|
Details |
40 bytes,
text/x-review-board-request
|
nalexander
:
review+
|
Details |
40 bytes,
text/x-review-board-request
|
nalexander
:
review+
|
Details |
I am finding, on some devices (see Bug 964854) that org.json.simple is just completely broken. I don't have any device that manifests this. But those tickets are top crashers that have been open for ages. I can provide some logs that support my conclusion.
I think it's time for org.json.simple to go. We used it because:
1) Android's org.json has a poor interface;
2) org.json doesn't work in our JUnit 4 tests (those not run on the device).
1) still applies. But we use org.json extensively in Fennec; there's no reason to keep our snow-flake here. I think 2) may have improved, and I'd like to think we could make roboelectric work with our tests.
So this ticket tracks:
* finding a configuration of the android-sync JUnit 4 tests that can run and use org.json, which is usually unhelpfully stubbed. This might Just Work in Gradle, or might need roboelectric, or a different unstubbing library.
* converting ExtendedJSONObject to use org.json. There are API mismatches here, so this takes manual effort.
* mopping up the last few org.json.simple uses (JSONArray, etc). Again, this takes manual effort.
The wins, though, are smaller code size, unification across the Fennec/android-sync divide, and fixing some catastrophic failures on many devices.
This is a good mentor ticket, but not a good first bug.
Comment 1•9 years ago
|
||
It would be great if this bug is solved since an increasingly amount of devices cannot use Sync anymore (like me, I have a MT6752 device).
Updated•9 years ago
|
tracking-fennec: ? → +
Whiteboard: [lang=java][bad first bug]
Assignee | ||
Comment 3•9 years ago
|
||
Bug 1182193 : Pre 1 -Update android gradle plugin to latest version r?nalexander
Attachment #8653127 -
Flags: review?(nalexander)
Assignee | ||
Comment 4•9 years ago
|
||
Bug 1182193 : Pre2 - Unit tests directory related changes r?nalexander
Ported TestDateUtils.java to use junit4 annotations.
Attachment #8653128 -
Flags: review?(nalexander)
Reporter | ||
Comment 5•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
https://reviewboard.mozilla.org/r/17369/#review15573
I have some issues, so this is just f+.
I think we might just roll this in to the next commit. We'll want some testing on the Gradle change, too.
::: mobile/android/gradle/base/build.gradle:31
(Diff revision 1)
> - exclude 'org/mozilla/gecko/tests/**'
> + exclude 'org/mozilla/gecko/tests/tests/background/**'
These paths must be wrong -- it can't be "tests/tests".
This is really part of the next commit, right? I.e., you're going to add a new directory of tests/background/junit4 or something? (I'm fine with pre-landing bits, just this one is odd.)
::: mobile/android/gradle/build.gradle:33
(Diff revision 1)
> // IntelliJ 14.0.2 wants 0.14.4; IntelliJ 14.0.3 and Android Studio want
The comment needs to be updated too.
Attachment #8653127 -
Flags: review?(nalexander)
Reporter | ||
Comment 6•9 years ago
|
||
Comment on attachment 8653128 [details]
MozReview Request: Bug 1182193 : Pre2 - Unit tests directory related changes r?nalexander
https://reviewboard.mozilla.org/r/17375/#review15575
This isn't quite what I'm after but it's a great start. Thanks for pushing into uncharted territory!
::: mobile/android/mach_commands.py:135
(Diff revision 1)
> + srcdir('base/src/test/java/org/mozilla/gecko', 'mobile/android/tests/unittest/src')
Ah, I see. We may have multiple unittest suites (like we have browser and background JUnit 3 / instrumentation suites).
So let's go ``mobile/android/tests/background/junit4/src`` or ``/unittest/src`` as you prefer.
::: mobile/android/tests/unittest/src/background/common/TestDateUtils.java:4
(Diff revision 1)
> +package org.mozilla.gecko.background.common;
Ah, I see what you did here. I'm sure this works, but this test in particular was written for device so that it can be used to time things. (See the disabled perf test.)
So it's not a good candidate for a JUnit 4 test. Try...
https://github.com/mozilla-services/android-sync/blob/develop/src/test/java/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java
or similar.
Attachment #8653128 -
Flags: review?(nalexander)
Assignee | ||
Comment 7•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 Pre: Gradle robolectric junit tests dependency added r?nalexander
Attachment #8653127 -
Attachment description: MozReview Request: Bug 1182193 : Pre 1 -Update android gradle plugin to latest version r?nalexander → MozReview Request: Bug 1182193 Pre: Gradle robolectric junit tests dependency added r?nalexander
Attachment #8653127 -
Flags: review?(nalexander)
Assignee | ||
Updated•9 years ago
|
Attachment #8653128 -
Attachment is obsolete: true
Assignee | ||
Comment 8•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 Pre: Gradle robolectric junit tests dependency added r?nalexander
Reporter | ||
Comment 9•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
https://reviewboard.mozilla.org/r/17369/#review15813
Nifty if it works. I prefer to put new code in the correct paths (for Gradle projects) right off the top, but we don't /have/ to.
::: mobile/android/tests/unittest/moz.build:7
(Diff revision 3)
> +sources= [
This won't work. Leave it for now, it's a little tricky. (And kill the other moz.build stuff.)
::: mobile/android/tests/unittest/src/fxa/TestSkewHandler.java:1
(Diff revision 3)
> +/* This Source Code Form is subject to the terms of the Mozilla Public
This didn't include the path changes.
mobile/android/tests/background/unittest/src/test/java/org/mozilla/gecko/fxa/TestSkewHandler.java
would be best. (Whew, what a mouthful!)
Attachment #8653127 -
Flags: review?(nalexander)
Assignee | ||
Comment 10•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 Pre: Gradle robolectric junit tests dependency added r?nalexander
* Moved robolectric test configuration to properties file.
* Moved login tests from android-sync to use robolectric
Attachment #8653127 -
Flags: review?(nalexander)
Reporter | ||
Comment 11•9 years ago
|
||
There are a few pieces to the test-porting part of this work. First, it's about:
* getting android-sync src/test into mozilla-central;
* configuring build.gradle to use Robolectric to run these as JUnit 4 unit tests without a device.
Second:
* it would be nice to build the src/test files in automation, to make sure that the tests don't bit rot (faster than the source code). This is like the JUnit 3 instrumentation tests in mobile/android/tests/{browser,background}: they don't get run automatically, but they are compiled. So the IDE tells you when you change the code, etc.
* it would be nice to build without requiring additional Robolectric, Mockito, test runner, etc JARs in the tree. Not a show-stopper, but better to just build the Java without new dependencies.
Third, and much harder:
* run the new JUnit 4 tests in automation. This is a long way out; see also Bug 1064004.
Reporter | ||
Comment 12•9 years ago
|
||
Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Attachment #8655696 -
Flags: review?(nalexander)
Reporter | ||
Comment 13•9 years ago
|
||
Comment on attachment 8655696 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Attachment #8655696 -
Flags: review?(nalexander) → review?(vivekb.balakrishnan)
Assignee | ||
Comment 14•9 years ago
|
||
https://reviewboard.mozilla.org/r/17979/#review16185
LGTM. May be we should change the reviewer in bug comment :)
Assignee | ||
Updated•9 years ago
|
Attachment #8653127 -
Attachment description: MozReview Request: Bug 1182193 Pre: Gradle robolectric junit tests dependency added r?nalexander → MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Assignee | ||
Comment 15•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Assignee | ||
Comment 16•9 years ago
|
||
Bug 1182193 - Part 2: Copy the tests from android-sync project. r?nalexander
Attachment #8656831 -
Flags: review?(nalexander)
Assignee | ||
Comment 17•9 years ago
|
||
Bug 1182193 - Part 3: Added runwith annotations for unittest with gradle r?nalexander
Attachment #8656832 -
Flags: review?(nalexander)
Reporter | ||
Comment 18•9 years ago
|
||
Comment on attachment 8656832 [details]
MozReview Request: Bug 1182193 - Part 3: Added runwith annotations for unittest with gradle r?nalexander
https://reviewboard.mozilla.org/r/18253/#review16371
This will need circulation and testing before landing, but it's looking great!
::: mobile/android/gradle/base/build.gradle:90
(Diff revision 1)
> + testCompile 'org.simpleframework:simple-http:4.+'
Always pin versions. This one should 4.1.13, it looks like.
::: mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestAccountAuthenticatorStage.java:17
(Diff revision 1)
> +import org.junit.runner.RunWith;
Based on https://github.com/junit-team/junit/wiki/Test-runners#runwith-annotation, it looks like we could have all tests inherit from a BaseTest class, and then annotate just that class. Can you see if this works? It would be nice to centralize the single test runner declaration.
Attachment #8656832 -
Flags: review?(nalexander)
Reporter | ||
Comment 19•9 years ago
|
||
> :::
> mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/
> TestAccountAuthenticatorStage.java:17
> (Diff revision 1)
> > +import org.junit.runner.RunWith;
>
> Based on
> https://github.com/junit-team/junit/wiki/Test-runners#runwith-annotation, it
> looks like we could have all tests inherit from a BaseTest class, and then
> annotate just that class. Can you see if this works? It would be nice to
> centralize the single test runner declaration.
vivek, on IRC:
10:23 vivek: [12:24:21] Some of the tests are written such a way that they extend from the class we are testing. These tests (eg :TestCommand
10:23 vivek: [12:25:08] Processor) access protected member of CommandProcessor class. Do you want me to modify these tests?
10:23 vivek: [12:26:40] I was planning to have a base interface to centralize @RunWith annotations but it feels like anti-pattern as interface does not define any contract.
This is a good point. Let's roll with the existing @RunWith annotations. With that, I think we're ready to post to the mailing list and land. vivek, could you draft a message to the list? I mostly want to publicize that we're bumping the Gradle plugin version and that we want reports of incompatibility with AS and IJ. The actual unittest stuff we can document separately.
Flags: needinfo?(vivekb.balakrishnan)
Assignee | ||
Comment 20•9 years ago
|
||
Comment on attachment 8653127 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
Assignee | ||
Comment 21•9 years ago
|
||
Comment on attachment 8656831 [details]
MozReview Request: Bug 1182193 - Part 2: Copy the tests from android-sync project. r?nalexander
Bug 1182193 - Part 2: Copy the tests from android-sync project. r?nalexander
Assignee | ||
Comment 22•9 years ago
|
||
Comment on attachment 8656832 [details]
MozReview Request: Bug 1182193 - Part 3: Added runwith annotations for unittest with gradle r?nalexander
Bug 1182193 - Part 3: Added runwith annotations for unittest with gradle r?nalexander
Attachment #8656832 -
Flags: review?(nalexander)
Assignee | ||
Comment 23•9 years ago
|
||
Bug 1182193 - Part 4: Disable unit test for regular gradle build tasks r?nalexander
Attachment #8660165 -
Flags: review?(nalexander)
Reporter | ||
Updated•9 years ago
|
Attachment #8660165 -
Flags: review?(nalexander) → review+
Reporter | ||
Comment 24•9 years ago
|
||
Comment on attachment 8660165 [details]
MozReview Request: Bug 1182193 - Part 4: Disable unit test for regular gradle build tasks r?nalexander
https://reviewboard.mozilla.org/r/19089/#review17013
::: mobile/android/gradle/build.gradle:64
(Diff revision 1)
> +// I bet there is a easier/cleaner way to do this, but this gets the job done for now.
Do you have a reference for this?
Please file a follow-up to make this check more clever. I'd like |gradle test| to do like this; but I'd also like to make |gradle base:test| restrict to the base project, and to make |gradle testDebugUnitTest| restrict to just the debug builds.
But definitely follow-up.
Reporter | ||
Comment 25•9 years ago
|
||
Comment on attachment 8656831 [details]
MozReview Request: Bug 1182193 - Part 2: Copy the tests from android-sync project. r?nalexander
https://reviewboard.mozilla.org/r/18251/#review17015
lgtm.
Attachment #8656831 -
Flags: review?(nalexander) → review+
Reporter | ||
Updated•9 years ago
|
Attachment #8653127 -
Flags: review?(nalexander)
Reporter | ||
Comment 26•9 years ago
|
||
vivek: run your last tests, address that one nit about pinning, and then land and post to the mailing list!
Let's take this bug for the test changes, update the title, and start a new one for the JSON bits. Great work!
Assignee: nobody → vivekb.balakrishnan
Status: NEW → ASSIGNED
Reporter | ||
Comment 27•9 years ago
|
||
Comment on attachment 8655696 [details]
MozReview Request: Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests. r?nalexander
This might be r=vivek? Can't recall.
Attachment #8655696 -
Flags: review?(vivekb.balakrishnan) → review+
Reporter | ||
Updated•9 years ago
|
Attachment #8656832 -
Flags: review?(nalexander) → review+
Assignee | ||
Comment 28•9 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/c02886680b09ced8b1c359ebf698b7f1ba827085
Bug 1182193 - Part 1: Add Gradle-based Robolectric JUnit 4 tests r=nalexander
Assignee | ||
Comment 29•9 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/45d1ea755875ff11ebf461206c707dc46e3d2b04
Bug 1182193 - Part 2: Copy the tests from android-sync project. r=nalexander
Assignee | ||
Comment 30•9 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/bceeacdb09f195cde005199dae3eab2ac44b3939
Bug 1182193 - Part 3: Added runwith annotations for unittest with gradle r=nalexander
Assignee | ||
Comment 31•9 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/ce211c03a51cadee6b45673394ec3cbfd620830f
Bug 1182193 - Part 4: Disable unit test for regular gradle build tasks r=nalexander
Assignee | ||
Updated•9 years ago
|
Flags: needinfo?(vivekb.balakrishnan)
Summary: Remove org.json.simple from android-sync code base → Add unit test support to fennec.
https://hg.mozilla.org/mozilla-central/rev/c02886680b09
https://hg.mozilla.org/mozilla-central/rev/45d1ea755875
https://hg.mozilla.org/mozilla-central/rev/bceeacdb09f1
https://hg.mozilla.org/mozilla-central/rev/ce211c03a51c
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox43:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 43
Updated•7 years ago
|
Product: Android Background Services → Firefox for Android
Updated•4 years ago
|
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•