One more thing any method you want to make a test append test as prefix with that method name. Where i only test to drop my Database if exist. So simple now we are ready to write our tests.Īfter that if you see on line 23 here i write my first test which is testDropDB. Now start disscussion on this DBTesting file.įirst if you see on line 14 we extend our class from AndroidTestCase. Now i am creating a new UnitTest file in this directory with name DBTesting.java We have one folder with Name androidTest. Now we are ready to check is our DB working.Īs you see directory structure. onUpgrade method is used when we update our app but we explain that method in some other tutorial □. So when App run first time the onCreate method automatically call and create our DB and Table. In onCreate we only create our table using SQL query. After that we got two abstract methods which we define onCreate and onUpgrade. If you see on line 13 we extends our DBHelper from SQLiteOpenHelper. Now see the below image of our DBHelper.java class. Here Helper means who help us to resolve our DB operations. Now DB mean database and Helper mean any thing which help us to resolve some issue. So simple I think we did not need to explain above class. Sorry it may be getting difficult so for the time being forgot about ContentProvider and next text :). When creating DB in any application, always create a File with name of Contract, where add all of your table’s meta data in static classes like Table name, Column names and when we move to ContentProvider at that time we also discuss to add CONTENT_URI and CONTENT_TYPE etc here. Create two new files one is DBContract and the second is DBHelper:ģ.1. Now we are creating an app in which we create a Simple DB with name school.db and create a single table with name Student.ģ. Result nothing again change some file and again repeat all steps.Īnd the great thing happen when after a some time we change some schema or add new table we again waste our time.Ġ. Some sharp devs use terminal but again waste there time using commands like: After that they open DDMS and go to file explorer and move one by one from directory structure: data /data / package-name/ databases/…. When mostly Android developers start working with SQLite, they waste a huge amount of time by testing “is DB created?” by launching Emulator or using Rooted Device. Here i am using Android Studio Beta 0.8 as an IDE. Now i am creating a tutorial on SQLite with Unit Tests in Android.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |