With AndroidX Test Framework now we can run Espresso test as unit test using Robolectric backend . But am confused when to use instrumentation test and when to use unit test.
Let's say we've two screens, MovieListActivity and MovieDetailActivity. when I click on an item in the MovieListActivity, details of that movie will be shown in the MovieDetailActivity.
Now with this scenario, what could be the possible unit tests and what could be the possible instrumentation tests?
For example, I can write instrumentation test to
- Check if the movies are listed
- Clicking on the movie goes to detail screen
- Detail screen displays the details correctly.
but now, these tests can be run as unit tests too, (since we're using Android X Test Framework) plus it's faster, as we're not running the test in a device/emulator. So what makes a test eligible for the instrumentation test?
What if I want to run a test as both unit test and instrumentation test?
As we're using Android X Test Framework the same unit test file can be run as an instrumentation test by copying the file to androidTest
folder. This makes duplicate file and makes the test case maintenance hard. (For example if I make an edit in the unit test
folder, the same modification should be done in androidTest
file.)
- Is there any way I can mark a test to run as both instrumentation test and unit test?
- If it's a bad practice, what's the best practice and what are other best practices should be considered when using Android X Test Framework?
Aucun commentaire:
Enregistrer un commentaire