mardi 12 janvier 2016

startActivity are not working in Android Unit Tests

I've tried everything already. The startActivity are not receiving the intent. Here's the code:

public class ColaboradorTeste extends ActivityUnitTestCase<ColaboradorMainActivity> {

    private UserDAO userDAO;
    private ColaboradorMainActivity activity;

    public ColaboradorTeste() {
        super(ColaboradorMainActivity.class);
    }

    @Override
    protected void setUp() throws Exception{
        super.setUp();

        startActivity(new Intent(getInstrumentation().getTargetContext(), ColaboradorMainActivity.class), null, null);

        activity = (ColaboradorMainActivity)getActivity().getApplicationContext();
        userDAO = new UserDAO(activity);
    }

    public void testBase() throws Exception{
     ...
    }
}

Here's the error:

java.lang.NullPointerException
    at br.fsw.seatafmobile.ColaboradorTeste.setUp(ColaboradorTeste.java:23)

I know the problem is in the startActivity, but I really don't know how to solve it. If anyone could help I'll really appreciate.

Aucun commentaire:

Enregistrer un commentaire