Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

As you may now, Robolectric is a framework that provides stubs for Android objects, in order to make tests runnable outside the Dalvik environment.

My concern is that, by doing this, one can fake a third party library, which is, I believe, not a good practice (it should be encapsulated instead). If you make assumptions about an interface you don't own, which is changed once your test has been written, you won't be always noticed about the modifications. This can lead to a misunderstanding between your implementations and the interface they depends on.

In addition, Android use mostly inheritance over interfaces which limits contract testing.

So here's my question: Are there situations when Robolectric is the way to go?

Here are some links you can check for further information:



share|improve this question
Can you make your question more specific, especially the title? As it stands, your question seems to be "should I use it? Does it have any merit?" which seems self evident, given that the thing exists. –  Robert Harvey Dec 4 '12 at 16:12
You're totally right and I'm sorry. I didn't planed to offend anyone with my question. I'm just looking for practical test cases when Robolectric is a suitable solution. –  Francis Toth Dec 4 '12 at 16:25
Not offended, just trying to help you out. –  Robert Harvey Dec 4 '12 at 16:47
Just a guess: perhaps this framework was created back when the arm-dalvik emulation was painfully slow and there was a speed benefit? As it stands it looks like your critique is valid and it's very hard to disagree with it. –  MrFox Dec 4 '12 at 16:54

1 Answer 1

up vote 1 down vote accepted

It seems suitable for projects that have large suites of very CPU-heavy tests that do not depend much on Android specifics. For instance, Roboelectric may care about some logging or similar statements.

For tapping user interfaces and watching for changes, Robotium on the emulator seems better.

However even better design may be to make the CPU-heavy classes completely Android - agnostic. Tests for such classes may run equally well under trivial JUnit under separate testing project.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.