I'm new at JUnit tests, I'm trying to test database access through this code:
public class SeuticketTest extends ActivityInstrumentationTestCase2<Seuticket> {
private Seuticket mActivity;
public SeuticketTest(String name) {
super("br.com.code.seuticket.android.view",Seuticket.class);
setName(name);
}
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = this.getActivity();
}
public void testTicketInsertion() {
Ticket ticket = new Ticket("123453", "Vip", new Date(), "Vila Country");
PersistenceTicket persistence = new PersistenceTicket(mActivity);
persistence.addTicket(ticket);
assertEquals(persistence.fetchTicket(ticket.getTicketCode()).getTicketCode(),ticket.get开发者_JAVA技巧TicketCode());
}
public void testUserInsertion() {
User user = new User();
user.setPin("1234");
user.setPhone("9241173");
PersistenceUser persistence = new PersistenceUser(mActivity);
persistence.addUser(user);
assertEquals(persistence.fetchUser().getPin(), user.getPin());
}
}
But my tests get stuck after complete the testTicketInsertion, the second test keep running forever, and sometimes before it run the tests this message shows at the console: Test run failed: Process crashed.
Any ideas? Hope to find an answer here. Thanks people!
I am brand new to JUnit testing in Android and ran into the same problem. Make sure you have the tearDown method overridden and are making the call to super.
protected void tearDown() throws Exception {
super.tearDown();
}
精彩评论