Android开发新手在使用Android Studio进行开发的时候遇到一个问题
我在开发一个app的时候用到一个以前没有使用过的控件,在代码敲完之后,想要测试一下可用性,但是数据来源于数据库,而数据库相关代码还没写好,请问怎么测试这个控件呢?或者是有其它更好更规范的开发方法?谢谢!
大家讲道理2017-04-18 09:06:41
I’m a novice with an undergraduate degree, so I’ll give this a forced answer, because what I wrote is all about demos and I haven’t made any actual products.
Database access operations are all SqlHelper
中进行的,getUsers
返回List<User>
。数据库方面还没确定代码的话,可以直接new
出一个模拟的List<User>
returned to the caller.
List<User> ret = new ArrayList<User>();
ret.add(new User(1, "Alice"));
ret.add(new User(2, "Bob"));
return ret;
迷茫2017-04-18 09:06:41
We usually use fake data for processing, like what is written above. There are many database frameworks for Android now, such as activeAndroid, realm, ormLite, which are very convenient to use and very powerful.
巴扎黑2017-04-18 09:06:41
The data is not very important, just simulate it directly. What you want to test is the control! !
天蓬老师2017-04-18 09:06:41
Generally this is called mock, which is to fake a similar interface, but the data is hard-coded in the memory. For example, you open an array to store all data, and then write a Mock class to provide a database interface. This can also be applied to network requests