Sugar ORM needs records to be saved every time while unit testing?
I am using Sugar ORM for db and Robolectric for unit testing. To use Sugar ORM with Robolectric i followed this question.
Where i put my code below in to startEverTestSugarAppAsFirst method and run.
new PersonHandler(new Activity()).insertPeople(); Person p = Person.findById(Person.class, 1); System.out.println(p.getName());
It prints the name of the first record. So far so good.
But if i comment out //new PersonHandler(new Activity()).insertPeople(); and run again no records are returned and null pointer exception is given. I thought that Sugar ORM stored records at the first run to somewhere and i can access to these records at the second time.
On the other hand, if I run the emulator where i put the code below in my main activity's onCreate method and in the second run with commenting out the first line I can see the first record printed in the log.
new PersonHandler(this).insertPeople(); Person p = Person.findById(Person.class, 1); Log.v("person", p.getName());
So, Does Sugar ORM delete db after unit test ends? or where it saves the db so i can use it over and over again?
It is not SugarORM but Robolectric. It creates temporary database every test so there is no hidden dependency between them.
This is good thing, your unit tests should be successfully run not dependent on order in which they are run