Search code examples
androidunit-testingjunitactivity-recognition

Android simulation of activityRecognition events


Is there a way to simulate / generate activity recognition events (i.e. - walking) in junits for a android application? My goal is to fully test the logic I have that is related to receiving an activity recognition event and not the activity recognition process.

Any pointers apprciated


Solution

  • I partially got around the issue by refactoring such that my detected activity is processed in it's own AsyncTask class. I then wrote a series of junits that could pass in a simulate event information to this activity detection processing class. Given that android has a limit on the number of asynctask executes that can be executed per object, my junit creates runnables in a loop to interact with the activity processing class.

    I also found the otto and dagger2 libraries that may work to inject events into the android bus. Still a work in progress though...