New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instrumented tests with the paging library #287
Comments
I have a similar question: https://stackoverflow.com/questions/50435770/how-do-i-create-a-pagedlist-of-an-object-for-tests |
You need to subclass the DataSource.Factory, and in the In LimitOffsetDataSource you must override |
@kekefigure I pretty much followed your instruction and my tests were working fine until I added |
@saied89 You mean BTW a full stack trace would be useful |
No I meant p.s: I'm so sorry for delayed response. |
@saied89 Your link above is no longer active. Do you still have a working solution available to share for mocking the |
Thanks @saied89! This is great. I'm working on putting a talk together on Android testing with Kotlin, JUnit 5, and MockK. The end result will be testing the ViewModel in a local unit test that mocks the Repository. I'm working on the proof of concept this week and will report back once it's working. I'm happy to provide you credit for this important piece! 🙂 |
That would be nice :). I'm pretty sure it's working. Not sure if there's
been an official solution in the mean time though. Good luck with the talk!
…On Wed, Sep 4, 2019, 5:48 AM AdamHurwitz ***@***.***> wrote:
Thanks @saied89 <https://github.com/saied89>! This is great. I'm working
on putting a talk together on Android testing with Kotlin, JUnit 5, and
MockK. I'm working on the proof of concept this week and will report back
once it's working. I'm happy to provide you credit for this important
piece! :-)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#287>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEZS2NIVLBLIXCFLKEVYAULQH4EGNANCNFSM4EL7VJUA>
.
|
Thank you @saied89! I'll follow-up with Google's @JoseAlcerreca who works on LiveData, after testing your solution. There ought to be an official solution as PagedList's are key to Android's architecture components. Also, you should post your solution to this related StackOverflow post. I'm happy to do so if you don't have the bandwidth and can link to your GitHub profile. |
Update @saied89 - Your implementation of the PagedList is working in my sample test outlined in this StackOverflow answer. The full sample code may be found in the Coinverse Open App. |
) * Update todo-mvp README.md Refactored the content around a new structure, with new standard titles used for each sample Fixed various grammar issues Applied formatting Additional explanations and links where appropriate Introduced pre-requisite topics * Update README.md Removed a redundant sentence. * copies Firebase Test Lab results to CIRCLE_TEST_REPORTS * Replaced deprecated attribute * Bumps versions and fixes annotation imports * Fixes toolbar title not being persisted after rotation * Fixes navigation issue android#287 * Bumps circle CI Android dependencies * Fixes comment in test * Bumps versions in travis.yml * Moving the setting of the AddEditTaskPresenter in the constructor. Tests added to check that the presenter is set to the view. * Removing the `_id` column and making `entryid` primary key. Moved the `TasksLocalDataSourceTest` to correct package. * Fixed Firebase Test Lab script * Tries to fix circle adding google repo * Buildtools 26 is mandatory now, apparently * More CI fixes * CI caught some merge errors + circle fix * Bumps versions to RC1, etc
* Update todo-mvp README.md Refactored the content around a new structure, with new standard titles used for each sample Fixed various grammar issues Applied formatting Additional explanations and links where appropriate Introduced pre-requisite topics * Update README.md Removed a redundant sentence. * copies Firebase Test Lab results to CIRCLE_TEST_REPORTS * Replaced deprecated attribute * Bumps versions and fixes annotation imports * Fixes toolbar title not being persisted after rotation * Fixes navigation issue android#287 * Bumps circle CI Android dependencies * Fixes comment in test * Bumps versions in travis.yml * Moving the setting of the AddEditTaskPresenter in the constructor. Tests added to check that the presenter is set to the view. * Removing the `_id` column and making `entryid` primary key. Moved the `TasksLocalDataSourceTest` to correct package. * First commit: MPV with Room * Readme updated * Readme updated * Fixing CI * Fixing tests for local repository * Using Idling resources for tests, for commands that are executed on the background thread * comments updated * Fixed Firebase Test Lab script * fix typo in androidTest * Fix typo (android#415) - Change "compliment" to "complement" * Fixed the typo (android#425) * Tries to fix circle adding google repo * Buildtools 26 is mandatory now, apparently * More CI fixes * CI caught some merge errors + circle fix * Updates todo-mvvm-databinding with changes from todo-mvp (android#437) * Update todo-mvp README.md Refactored the content around a new structure, with new standard titles used for each sample Fixed various grammar issues Applied formatting Additional explanations and links where appropriate Introduced pre-requisite topics * Update README.md Removed a redundant sentence. * copies Firebase Test Lab results to CIRCLE_TEST_REPORTS * Replaced deprecated attribute * Bumps versions and fixes annotation imports * Fixes toolbar title not being persisted after rotation * Fixes navigation issue android#287 * Bumps circle CI Android dependencies * Fixes comment in test * Bumps versions in travis.yml * Moving the setting of the AddEditTaskPresenter in the constructor. Tests added to check that the presenter is set to the view. * Removing the `_id` column and making `entryid` primary key. Moved the `TasksLocalDataSourceTest` to correct package. * Fixed Firebase Test Lab script * Tries to fix circle adding google repo * Buildtools 26 is mandatory now, apparently * More CI fixes * CI caught some merge errors + circle fix * Fixed Firebase Test Lab script (android#440) * Updates room branch to API 26, Espresso, Arch Components * Adds google m2 repository * Adding google() to repositories * Reverts to todo-mvp's README * No need for LicecycleActivities now
In addition to the solutions mentioned above, Paging3 now offers |
Thanks for the update Dustin! I'm happy to hear that local JUnit 5 tests will be easier moving forward with Paging3. |
Hi!
I'm trying to do instrumented test on an app that is based on the architecture components. The testing environment is the same as in the github browser sample (no dagger2 injections, SingleFragmentActivity).
My dao returns a DataSource.Factory<Integer, ModelSomething> and with the LivePagedListBuilder i get a LiveData<PagedList> object in the repository. I'm observing this livedata in the fragment, and replace the adapters list on data changes.
It was easy without the Paging library, but now it seems a bit more complicated.
How should be the PagedList mocked, without creating an in memory databse to get the DataSource.Factory, then creating a LivePagedListBuilder to get PagedList object which contains the test data (which need to be inserted first to get some result)?
Thanks
The text was updated successfully, but these errors were encountered: