reset password
Author Message
ngosrani
Posts: 31
Posted 17:31 May 21, 2016 |

Hello Professor,

For the very first time when I ran my test, both test passed and now when I re-run the test I get an error saying :

Running tests
Test running started
junit.framework.AssertionFailedError: Error: Movie Info Not Inserted Correctly
at com.....moviereview.data.DataBaseTest.testInsertReadRow(DataBaseTest.java:43)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1886)

Finish

 

and under Android Monitor tab it says:

 

05-21 20:27:52.324 31594-31615/com.....moviereview I/TestRunner: started: testInsertReadRow(com.....moviereview.data.DataBaseTest)
05-21 20:27:52.338 31594-31615/com.....moviereview E/SQLiteDatabase: Error inserting publish_date=2016-05-12 summary_short=Ben Wheatley adapts J.G. Ballard 2019s futuristic novel about a residential building that descends into decadence and barbarism. display_title=High-Rise
                                                                                 android.database.sqlite.SQLiteException: no such table: reviews (code 1): , while compiling: INSERT INTO reviews(publish_date,summary_short,display_title) VALUES (?,?,?)
                                                                                     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                                     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                                                     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                                                                                     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                                     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                                     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                                                                                     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
                                                                                     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
                                                                                     at com.....moviereview.data.DataBaseTest.testInsertReadRow(DataBaseTest.java:42)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at junit.framework.TestCase.runTest(TestCase.java:168)
                                                                                     at junit.framework.TestCase.runBare(TestCase.java:134)
                                                                                     at junit.framework.TestResult$1.protect(TestResult.java:115)
                                                                                     at junit.framework.TestResult.runProtected(TestResult.java:133)
                                                                                     at junit.framework.TestResult.run(TestResult.java:118)
                                                                                     at junit.framework.TestCase.run(TestCase.java:124)
                                                                                     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
                                                                                     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
                                                                                     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
                                                                                     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1886)
05-21 20:27:52.340 31594-31615/com.....moviereview I/TestRunner: failed: testInsertReadRow(com.....moviereview.data.DataBaseTest)
05-21 20:27:52.343 31594-31615/com.....moviereview I/TestRunner: finished: testInsertReadRow(com.....moviereview.data.DataBaseTest)
05-21 20:27:52.344 31594-31615/com.....moviereview I/TestRunner: started: testAndroidTestCaseSetupProperly(com.....moviereview.data.DataBaseTest)
05-21 20:27:52.345 31594-31615/com.....moviereview I/TestRunner: finished: testAndroidTestCaseSetupProperly(com.....moviereview.data.DataBaseTest)
05-21 20:27:52.346 31594-31615/com.....moviereview I/TestRunner: passed: testAndroidTestCaseSetupProperly(com.....moviereview.data.DataBaseTest)

Last edited by ngosrani at 17:32 May 21, 2016.
msargent
Posts: 519
Posted 15:12 May 22, 2016 |

"android.database.sqlite.SQLiteException: no such table: reviews (code 1)" seems to be the problem. Did you delete the tables?  If so, check to see if onCreate in SQLiteOpenHelper got called when you ran your tests. Also check to see if your create table sql strings have the correct syntax --- Log them and check syntax using an SQL syntax checker (try http://sqlfiddle.com/#!5). Also, make sure the table name is the same throughout your code (always use the contract class's constants).

One way to force onCreate to run when checking on an emulator is to delete the database file (we talked about getting that file in lecture using the Android Device Monitor). If you forgot how, google it. 

Last edited by msargent at 15:15 May 22, 2016.