Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Testing syncadapter

I have a sync adapter that is synchronizing the contacts with a private server. It looks something like the SampleSyncAdapter in the samples (but of course modified to meet my needs).

I need to write tests for this sync adapter. Can anyone give me some guides on how to write these tests?

I got stuck with testing the contacts operations (create, update, delete). How can I mock the contacts database so I can that one for testing instead of the the real contacts database?

Thank you

like image 744
nikmin Avatar asked Nov 12 '13 10:11

nikmin


People also ask

What is syncadapter in Android?

The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.

What is offline synchronization in android?

Offline sync allows end users to interact with a mobile app—viewing, adding, or modifying data—even when there's no network connection. Changes are stored in a local database. Once the device is back online, these changes are synced with the remote backend.

Where is main method in Android?

The main() method is in the Android framework class android. app. ActivityThread . This method creates the Main (UI) Thread , sets up a Looper on it and starts the event loop.


1 Answers

I couldn't find solution for this, so I decided to create new account in setUp(), run the tests and delete the account at the end. This way I can test the operations with the real database but in different account. So I can run my tests, but without changing the existing contacts.

like image 192
nikmin Avatar answered Sep 18 '22 16:09

nikmin