0

I've written a real-time subsystem for Android that I'd like to test on the desktop. I would like to run tests via a command line tool of my creation. The subsystem depends on Android as follows:

  • android.os.Looper
  • android.os.Handler (including Handler.Callback)
  • android.os.Message
  • android.util.Log

I need to stub these classes. Robolectric stubs these classes but apparently doesn't allow for custom instances of Looper. Unless someone can point me to functional stubs, I plan to write them myself. I'd rather avoid the complexity of writing a test harness for a full Android emulator.

How do I get Android Studio to use my stubs for these classes in my tool build? I don't want to modify the subsystem to dynamically receive the classes it should use, out of fear of limiting optimization or making code unnecessarily messy. (But I am open to wrapping android.util.Log.)

Thanks for your help!

Community
  • 1
  • 1
Joe Lapp
  • 2,435
  • 3
  • 30
  • 42
  • 1
    Dépends on how you've implemented the use of the libraries listed. You can check: http://stackoverflow.com/questions/37249744/not-able-to-stub-post-method-of-android-os-handler-class for some hints. – JFPicard Jan 13 '17 at 18:53
  • Okay thanks. Looks like there might be a solution with `@MockInjects`, if Mockito doesn't impose too much of a framework. Looking into it, but I'd still love a direct answer! – Joe Lapp Jan 13 '17 at 19:30
  • Ha! I've thought of a better approach: don't use Android Studio. Duh! – Joe Lapp Jan 13 '17 at 19:41

0 Answers0