Dennis Jaamann
Dennis Jaamann

Reputation: 3565

AndroidAnnotations and Unit Testing

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,

Upvotes: 3

Views: 2618

Answers (1)

John Ericksen
John Ericksen

Reputation: 11113

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.

Upvotes: 3

Related Questions