An alternative solution is to avoid using ApplicationTestCase or AndroidTestCase or any other class that depends on Context . The fact is that there is no need to test the SQLite or ORM structure so that you can create an interface using the basic CRUD methods:
public interface UsersManager{ User createUser(String userId); User getUser(String userId); boolean updateUser(User user); boolean deleteUser(User user); }
And implement two versions: one for the tests and the other for the production version. The test version can be easily implemented using the HashMap :
public class TestUsersManager implements UsersManager{ private HashMap<String, User> users = new HashMap(); public User createUser(String userId){ User result = new User(userId); users.put(userId, user); return result; }
It works fast (without an IO disk in the case of SQLite ) and has no external dependencies. By the way, this is also an additional level of abstraction: for production code, you can easily switch between ORM frames.
eleven Feb 04 '16 at 16:11 2016-02-04 16:11
source share