测试Android上的SQLite数据库 [英] Testing a SQLite database on Android

查看:117
本文介绍了测试Android上的SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的JUnit测试为我它使用SQLite数据库Android应用程序。我需要创建可通过测试用例进行操作测试数据库。该数据库需要在一个已知的配置来启动和重置每个测试用例。我想通了,我可以通过传递SQLiteOpenHelper一个值作为文件名数据库(的看到这篇文章的详细信息)。现在,我也想填充数据库表中的一些我的测试。我有一些数据,我可以用于测试我的本地文件系统中的CSV文件。如何获得这些数据转化为我的SQLite数据库上进行测试仿真器或其他设备?

I am working on JUnit tests for my Android app which uses a SQLite database. I need to create a test database which can be manipulated by test cases. The database needs to start in a known configuration and reset for each test case. I figured out that I can use an in-memory database by passing the SQLiteOpenHelper a null value as the file name for the database (see this article for details). Now I also want to populate the database table for some of my tests. I have a CSV file on my local file system with some data that I can use for testing. How do I get this data into my SQLite database on an emulator or other device for testing?

推荐答案

有没有内置在SQLite库code CSV导入功能。

There is no built-in CSV import function in the SQLite library code.

不过, 的sqlite3 命令直插式工具可以导入CSV文件。导入后,你有一个数据库文件,你可以只复制到您的设备符合亚行工具。
另外,您也可以使用的sqlite3的使用.dump 命令生成的SQL命令来重新创建数据库;然后你把它们放入一个字符串数组,或把它们放到你的测试程序读取的文本文件。

However, the sqlite3 command-line tool can import CSV files. Once imported, you have a database file that you can just copy to your device with the adb tool. Alternatively, you can use sqlite3's .dump command to generate the SQL commands to recreate the database; you then put them into a string array, or put them into a text file read by your test program.

这篇关于测试Android上的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆