Closed
Bug 938824
Opened 11 years ago
Closed 11 years ago
Remove reflection from testSearchSuggestions
Categories
(Firefox for Android Graveyard :: Testing, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 30
People
(Reporter: mcomella, Assigned: mcomella)
References
Details
Attachments
(1 file, 2 obsolete files)
(deleted),
patch
|
mcomella
:
review+
|
Details | Diff | Splinter Review |
Reflection is used to change the access levels (e.g. protected, public) on certain members of this class. Really, the class should be declared protected, extended by a mock class exclusive to testing, and accessors to these otherwise hidden fields added to this mock.
Assignee | ||
Updated•11 years ago
|
Component: General → Testing
Assignee | ||
Comment 1•11 years ago
|
||
I did the easy stuff.
It seems difficult to remove the later reflection using a MockBrowserSearch
since BrowserSearch is constructed in BrowserApp.onCreate, which means
BrowserApp would need to be mocked, which means we're testing a different
Activity and the majority of the code in BaseTest.setUp would have to be duped
in a sub-class.
BrowserApp.onCreate calls BrowserSearch.newInstance statically, which means
this could be replaced with a call to a BrowserSearchFactory.newInstance,
where newInstance will return either a regular BrowserSearch instance or an
overriding mock class.
What do you think?
Attachment #8342743 -
Flags: review?(nalexander)
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → michael.l.comella
Status: NEW → ASSIGNED
Assignee | ||
Comment 2•11 years ago
|
||
Comment on attachment 8342743 [details] [diff] [review]
Part 1: Create SuggestClient without reflection.
Nevermind, I apparently forgot to compile. x_x
This is harder than I thought because SuggestClient is package private. Should we make it public?
Note to future travellers: do not remove the @RobocopTarget annotation.
Attachment #8342743 -
Flags: review?(nalexander)
Assignee | ||
Updated•11 years ago
|
Flags: needinfo?(nalexander)
Comment 3•11 years ago
|
||
Comment on attachment 8342743 [details] [diff] [review]
Part 1: Create SuggestClient without reflection.
Review of attachment 8342743 [details] [diff] [review]:
-----------------------------------------------------------------
lgtm. Are there more parts to come?
::: mobile/android/base/home/SuggestClient.java
@@ -54,5 @@
> mCheckNetwork = true;
> }
>
> /**
> * This constructor is used exclusively by Robocop.
This comment says what @RobocopTarget enforces. Explain why there's a different constructor or remove the comment.
Attachment #8342743 -
Flags: review+
Comment 4•11 years ago
|
||
(In reply to Michael Comella (:mcomella) from comment #1)
> Created attachment 8342743 [details] [diff] [review]
> Part 1: Create SuggestClient without reflection.
>
> I did the easy stuff.
>
> It seems difficult to remove the later reflection using a MockBrowserSearch
> since BrowserSearch is constructed in BrowserApp.onCreate, which means
> BrowserApp would need to be mocked, which means we're testing a different
> Activity and the majority of the code in BaseTest.setUp would have to be
> duped
> in a sub-class.
>
> BrowserApp.onCreate calls BrowserSearch.newInstance statically, which means
> this could be replaced with a call to a BrowserSearchFactory.newInstance,
> where newInstance will return either a regular BrowserSearch instance or an
> overriding mock class.
>
> What do you think?
So, this approach seems more hairy than it's worth.
Is there a reason to not allow Robocop to set the client directly with something like BrowserSearch.setSuggestionClient()? We already have work-arounds in place, like at http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/home/BrowserSearch.java#507. We document that setSuggestionClient is private and for Robocop and then we move on. What am I missing?
Flags: needinfo?(nalexander)
Comment 5•11 years ago
|
||
> Is there a reason to not allow Robocop to set the client directly with
> something like BrowserSearch.setSuggestionClient()? We already have
> work-arounds in place, like at
> http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/home/
> BrowserSearch.java#507.
And maybe we only allow setting if the existing value is null, to prevent bad things.
Assignee | ||
Comment 6•11 years ago
|
||
Attachment #8375898 -
Flags: review?(nalexander)
Comment 7•11 years ago
|
||
Comment on attachment 8375898 [details] [diff] [review]
Create and set SuggestClient in testing without reflection.
Review of attachment 8375898 [details] [diff] [review]:
-----------------------------------------------------------------
If it's green locally and on try, it looks good to me.
::: mobile/android/base/home/BrowserSearch.java
@@ +547,5 @@
> + /**
> + * Sets the private SuggestClient instance. Should only be use for testing purposes.
> + */
> + @RobocopTarget
> + public void setSuggestClient(final SuggestClient client) {
Consider using this in whatever code sets the suggest client already.
Attachment #8375898 -
Flags: review?(nalexander) → review+
Assignee | ||
Comment 8•11 years ago
|
||
green on try after taking the suggestions in comment 7: https://tbpl.mozilla.org/?tree=Try&rev=13c63ab92f52
Assignee | ||
Updated•11 years ago
|
Attachment #8375898 -
Attachment is obsolete: true
Assignee | ||
Comment 9•11 years ago
|
||
Comment on attachment 8376361 [details] [diff] [review]
Create and set SuggestClient in testing without reflection.
Review of attachment 8376361 [details] [diff] [review]:
-----------------------------------------------------------------
Move r+.
Attachment #8376361 -
Flags: review+
Assignee | ||
Updated•11 years ago
|
Attachment #8342743 -
Attachment is obsolete: true
Assignee | ||
Comment 10•11 years ago
|
||
https://hg.mozilla.org/integration/fx-team/rev/0beafa155ee9
Goodbye, reflection.
Comment 11•11 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → Firefox 30
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
•