Skip to content

Unit test your application

pyricau edited this page May 25, 2012 · 4 revisions

You should start by reading the Testing chapter in the Android documentation.

You may run your tests on a real environment, such as an emulator or a device. However, if you need fast running tests, you should definitely have a look at Robolectric an out-of-container test frameworks that runs within JUnit. It is absolutely needed if you use a continuous test runner, such as infinitest.

For instrumentation / integration tests, have a look at Robotium.

At first, you may find it hard to unit test your components written using AndroidAnnotations. Here are a few key points that should help you:

  • The usual way to unit test a component that has dependencies is to replace its dependencies with dummy, fake, stub or mock objects.
  • There's no way to tell AndroidAnnotations that you want to inject mocks instead of real objects, because it works at compile time, so the code must always be production ready.
  • You should test the generated classes (e.g. MyActivity_), not the annotated ones (e.g. MyActivity). The annotations are adding behavior to your code, so you shouldn't test it as if there were no annotation.
  • Test your activities behavior, not AndroidAnnotations' behavior. The framework already has tests of its own to check that the annotations work correctly.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally