Skip to content
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

Can not have more than 1 content provider testcase #1082

Closed
rockerhieu opened this issue May 17, 2014 · 3 comments
Closed

Can not have more than 1 content provider testcase #1082

rockerhieu opened this issue May 17, 2014 · 3 comments

Comments

@rockerhieu
Copy link

Hey guys,

Thanks for the amazing work on this useful library.

Currently, I'm experiencing a bug with version 0.10.+. I can test CRUD for Content Provider using ShadowContentResolver (as an example here http://stackoverflow.com/questions/18022923/robolectric-contentprovider-testing).

But if I add more test cases, only the 1st work, the rest will be failed. So I did a workaround by having only 1 fat test case which covers all the cases of CRUD for my ContentProvider. W00t, everything works fine.

Later on, I had to implement another ContentProvider, so I did the same: having another Test class whose 1 fat test case. This test case simply doesn't work, it always failed. After hours of debugging, I found out that the temporary database created by Robolectric will be closed and deleted after the first test case run.

Anyone else got the same issue while testing ContentProvider with Robolectric?

@rockerhieu
Copy link
Author

Turned out it was because in the ContentProvider, I initialized SQLiteOpenHelper using singleton pattern. It causes Robolectric failed to recreate the database for each test.

@twmht
Copy link

twmht commented Mar 24, 2016

hi,

how did you solve the problem?

I face the same problem in #2387

@rockerhieu
Copy link
Author

@twmht I initialised a new SQLiteOpenHelper for each ContentProvider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants