0

Disclaimer: this is my first ever Android test project with Robotium.

I'm facing a catch-22 situation with ActiveAndroid and Robotium. Here's my setup:

  1. I want to test an activity that expects a long array extra. This array contains DB ids of ActiveAndroid objects.
  2. To get the ActiveAndroid objects ids', I need to initialize ActiveAndroid first, calling ActiveAndroid.initialize(this.getActivity()) from my ActivityInstrumentationTestCase2 class.
  3. The call to getActivity() fails since I didn't pass the long array extra. I can't create the long array extra because I haven't initialized ActiveAndroid, hence the catch-22.

Is there another way I can get a context in a test class? An application-wide context perhaps?

jlhonora
  • 10,179
  • 10
  • 46
  • 70

1 Answers1

0

I found the solution:

ActiveAndroid.initialize(this.getInstrumentation().getTargetContext());

That way you can get the target's context before initializing the activity.

jlhonora
  • 10,179
  • 10
  • 46
  • 70
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – davidsbro Oct 24 '14 at 12:51
  • Why isn't it an answer? I'm getting a suitable context without instantiating the Activity first. – jlhonora Oct 24 '14 at 14:32