tags:

views:

123

answers:

1

I have separated most of my android game code into a separate reusable 'Java Project'. The 'Android project' basically starts a surface View and then loads a new thread containing necessary object from my external 'Java Project'.

How could I run JUnit tests on this considering the external 'Java Project' needs an application context.

I don't want to do the unit testing in the Android Project because I may have 3+ different projects all using the code from the 'Java Project'.

A: 

If you only need a Context to initialize everything without calling real method on the Context you could use a Mock/Stub, a fake Context object that simply has the interface but does nothing.

My advice though would be to separate the code even more. Try to move as much code as possible away from the android depended classes. In this way you can have some nice clean JUnit4 tests to test the logic. Then in the android project you take some android Junit tests and check if those things run on android.

Janusz
Thanks, how do I make a mock Context object? Also, when I create some of my objects I pass drawable references to the external classes. For example, I have a Room class and I pass the context, the background image and a background mask from my drawable.
jax
I yet haven't used it in android context, but I would recommend http://easymock.org/ for generating mocks.
Janusz