简体   繁体   中英

Android JUnit Test with SQLCipher for Android

in my app, i use SQLCipher to encrypt my database. At first, i forgot to add the icudt46l.zip to my apps asset folder and i got an exceptions saying net.sqlcipher.database.SQLiteException: not an error

This was easy to fix since i only had to copy the file to the assets folder. Now my app is nearly finished and i need to write some automated tests. For the beginning, i thought JUnit tests would be a good choice. So i created a simple ActivityUnitTestCase to start with. Unfortunately every time i start the test, i get the net.sqlcipher.database.SQLiteException: not an error again.

I hope you can tell me what i am doing wrong. I copied the icudt46l.zip to my test projects asset folder as well but this time it didn't fix it.

SQLCipher for Android was built to run directly on a device/simulator, whereas JUnit tests typically run directly within the desktop Java VM. We have found it helpful to be able to test SQLCipher for Android on various devices/Android platforms and use a separate application as the test suite. More information about the test suite can be found here .

Today something happend which i cannot understand nor can i explain it. I just deleted the App from all my devices/emulators and re-installed it. After this step, I was able to run the Android JUnit test without getting the error. I have no idea what changed but now it works fine.

As Nick Parker said, a normal JUnit test would run directly in the JVM but on Android, JUnit test are a little bit different. They need a device or emulator to run. This is the reason why i cannot use Robolectric for my JUnit tests but the plain Android JUnit test works now.

Currently I have a mix between TestCases for my POJOs, ActivityUnitTestCases for testing my activities layout and ActivityInstrumentationTestCase2s for functional testing. Also I use Robotium for my functional testing.

Again, I have no explanation why it now works but to be true: I don't really care as long as it works. So.. if somebody has the same strange behaviour, I only can recommend to remove the App and install it again right before running the tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM