DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

Create a mock to test with junit

Open arturonaredo opened this issue 11 years ago • 9 comments

Is there a way to test DBFlow without passing a context or a mockcontext (right now is giving us a NPE) to test it with mock data? Maybe passing a db file or something?

We want to create junit tests and and unit tests should not know nothing about context nor other android stuff...

arturonaredo avatar Jun 15 '15 16:06 arturonaredo

+1

felipehjcosta avatar Jun 16 '15 22:06 felipehjcosta

Great idea, that would be really helpful :)

jesdiart avatar Jun 24 '15 16:06 jesdiart

Not currently, you need to get a handle on the database to use it, since it operates using the FlowSQLiteOpenHelper

agrosner avatar Jun 30 '15 00:06 agrosner

you can use roboelectric to do that, http://robolectric.org/

agrosner avatar Jun 30 '15 00:06 agrosner

@arturonaredo I've successfully mocked both Context and SqlUtils in this example. Will update the sample to 2.2.1 when I get the chance.

kaeawc avatar Jul 19 '15 14:07 kaeawc

Here's the short helper class that makes it possible: SqlUtilsMock

This lets you mock a table for the duration of a test.

Let me know if that works for you or if you have any problems.

kaeawc avatar Jul 19 '15 14:07 kaeawc

@kaeawc do you still have your example ? unfortunately both links you gave are deads.

mathroule avatar Mar 31 '16 22:03 mathroule

+1

arctouch-luizsantana avatar Dec 08 '16 17:12 arctouch-luizsantana

Does anybody have a backup of this code (SqlUtilsMock)?

rosmons avatar Feb 22 '17 23:02 rosmons