Domanda

Mi sembra che robotium è stato progettato in modo da test 1 attività alla volta invece di tutta l'applicazione.

Quindi la mia domanda è: come faccio a testare un'attività che si aspetta un extra da passare ad esso? da I più intent.putExtra("Something", object); media

È stato utile?

Soluzione

The method setActivityIntent(Intent) should be what you are looking for. I used this method to provide a custom Intent to my Activity's TestCase. Just use it after you call super in your constructor.

Intent i = new Intent();
i.putExtra("myExtra", "anyValue");
setActivityIntent(i);

You don't have to do it in the constructor i think, but you need to make sure that you call it before you call getActivity() for the first time. getActivity will use your Intent to create the Activity.

Altri suggerimenti

You could override getActivity() instead.

@Override
public NewActivity getActivity() {
    Intent intent = new Intent();
    intent.putExtra("exampleExtra", "some data");
    setActivityIntent(intent);
    return super.getActivity();
}

See Testing for Android with Robotium for more details.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top