3

I am using AndroidAnnotations(2.5) in a sample project I am currently working on.

Since you can annotate your classes with for example @EActivity,@ViewById,@Click which will all lead to generated compile-time code, I was wondering how one would go about creating unit tests / functional tests for any Android Annotations powered application.

I would love to hear some opinions on this matter.

Cheers,

Dennis Jaamann
  • 3,547
  • 2
  • 23
  • 42

1 Answers1

3

I responded to a similar post here.

There are a couple of options available to you. You can, of course, test your code pre-generation in, what I claim, is a more unit testing style. This should test the Java code in isolation, preferably without generated code involved.

You can also test the code post-generation. The MyActivity_ classes generated by AA can be instantiated directly after compile time and test them accordingly. I claim this is edging towards an integration testing style.

While, I think it is always better to test than not to test, I think for integration tests, you should test on the hardware in a situation similar to production. This gives you a total picture of how your application will behave in a real world situation. Thus, for integration tests I prefer high level "is everything working well together" tests.

Robolectric and Robotium can help greatly in these two efforts. Robolectric allows you to instantiate you Activities in a unit test, while Robotium allows you to test selenium style directly on a device.

To recap, I prefer to heavily unit test my code without generation then do some light integration testing to make sure everything is working well together.

Community
  • 1
  • 1
John Ericksen
  • 10,995
  • 4
  • 45
  • 75
  • Well basically, I would be more inclined to unit test the generated code since that is the code that will be executed and that you will be packaging into your apk and deploying on the Play store as well. Does that make sense or not? – Dennis Jaamann May 16 '12 at 15:19
  • Makes sense to me. This is the scenario I described in the second paragraph. – John Ericksen May 16 '12 at 17:07
  • Also see [this answer](http://stackoverflow.com/a/10666453/703646) on the post pointed out by @johncarl. – Pierre-Yves Ricau May 19 '12 at 15:21