-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Roboelectric for unit testing? #115
Comments
I too have not used Roboletric in any significant way, but at the moment I can't see a place for it; given the improvement in JVM testing tools for Android and patterns such as MVP/MVVM that separate logic from platform dependencies. I can't comment on performance, but the real issue for me is that the tests run against an approximation of Android in code that you can't control. For all the boilerplate your get in wrapping, at least you control the contract. See #114 |
My biggest problem with using Roboletric is that it is provided by 3rd party company. So if you now have Android N then you still need to wait for their implementation, which can take time and might not behave as a real device. The other thing is that you shouldn't use it for Unit Tests as those are not Unit Test if you rely on the whole 3rd party implementation framework. For Integration Tests using the real software seems like a better idea.s P.S. Making your own code independent from Android framework is also a good mental exercise. |
This is a good point about Robolectric having to play catchup with APIs and implementation. |
Roboelectric is not a good approach to unit testing. App should be design in such way that business logic can be tested with junit and only some mocks. Use dependency injection in your app design, don't mess entities and business logic with |
Sounds like we are all in agreement on this one. |
First of all I am using Roboelectric and I hate it, but it is useful and I will share why :) there several statements here which are kind of too generic and not clear to me. There is not question about that Business logic should be done in a way that it has almost and preferably no external dependencies, however there is also Application Specific Business Logic, which needs to be tested as well. There is a bit confusion what is a Unit Test and the confusion is in 2 main points:
Having said that Unit Tests may involve some android components. So 'Unit Tests may involve some android components'. Normally you should not mock 3rd party code(just the adapters connecting to it) as you don't know in detail how it works. Robolectric guys do exactly this and its pretty big one. They do an awesome job and yet I prefer test with a Real device using Espresso. The problem is using TDD and running tests constantly could be terribly slow so Roboelectric is of real help here. So Roboelectric can be used for unit tests which involves android components and its way faster than Espresso (the fastest currently real UI framework) |
What about Espresso and the new Espresso Test Recorder in Android Studio 2.2? |
i tried the recording and i like it. its a bit slow but quite helpful. however i believe espresso is already mentined in #114 |
So can some explain when i should roboelectric and when i should espresso ? I'm confusing to choose the exactly testing tool. |
IMO use roboelectric when you want UI related tests to pass fast for example during TDD cycles. Note that the main idea is to spend less time in code and tests but do more features (test covered of course) . So if using some framework is taking to much time to set up and run and the tests are flaky then you probably do not use it right or the framework is not meant to be used this way. |
I was in the Droidcon a couple of days ago and there was a talk about why not to use Roboelectric. Basically what he said is that it makes the tests slow and when you use it only for unit testing and not for views (what we recommend), doesn't provide anything you could not do yourself.
I don't have experience with Robolectric myself, I never needed it, if my class uses some Bundle or framework related stuff I just wrap it.
So my question: is really a good practice to use Robolectric when it makes your tests slow and it is possible to live without it?
The text was updated successfully, but these errors were encountered: