breathingdust
breathingdust

Reputation: 205

Is there any point in using a Java module for unit tests in an Android project?

When developing for Android, is there any point to having a test project as a normal Java module, so when run doesn't actually run on the emulator/device?

I had the idea to create an Android test project/module for items which depend on Android context, and a normal Java project/module for tests which have no reliance on Android itself.

Is it worth doing this or am I opening myself up for potential pain by not having the test code run on the device.

Note I come from a .Net background so my Java experience is pretty slim.

Upvotes: 2

Views: 97

Answers (3)

Dmitry
Dmitry

Reputation: 17350

This is a valid approach. Also Roboelectric is a unit testing framework that addresses the main issue that you mentioned (slowness of tests executed on emulator). Might be worth checking out. There are also quite a few related answers in this question.

Upvotes: 2

jcxavier
jcxavier

Reputation: 2232

Android Developer has those topics covered, both in Hello, Testing and Testing Fundamentals.

Upvotes: 0

macduff
macduff

Reputation: 4685

When I develop for Android, I find this very helpful. There are some functions that do not require hardware based events, but just data. If you can come up with robust test data, this can be an easy, painless way to regression test your code and be confident that you haven't introduced any bugs into existing components.

Upvotes: 2

Related Questions