Tests can be run with Robolectric for Android tests.
Todo:
[X] Get project able to run Robolectric tests. This means installing java11 via homebrew and setting java11 as JRE in Android Studio to run robolectric tests.
[X] Move tests to sharedTests/ directory so Android can run tests and Robolectric can too.
[ ] Get all tests passing with Robolectric. Note: Some tests are not passing because of super easy Mockito changes to the syntax. Easy. Other tests are because of Robolectric and it's looper to get everything running correctly with threading. Especially trying to get Teller integration testing setup code working. I am trying to write e2e UI tests using Robolectric essentially.
I am thinking that: Robolectric tests are great for unit tests. We test the UI of our code as unit tests (does X view exist?) kind of stuff. With this in mind, we want to decide to change the way we are running these tests (which will fix the problems we are currently facing). Instead of trying to use Teller initialization, for example, we save that only for the Android UI tests code that tests the UI with screenshots while we mock the ViewModel layer for robolectric unit tests?
This idea came from iOS where I write unit tests for the Views of the app and View controllers (fragments/activities essentially) and I mock the ViewModel for the unit tests just to test that certain views are shown and others are not. I concentrate my tests on just the 1 View class. True Android integration tests should run on the device because it's as close to the real thing as possible by running on the device. Also, we don't need to deal with the whole mess of robolectric. These tests can take screenshots, can test E2E fully, and can run on the device. Having this separation would be great for many benefits that I personally see when I do iOS dev. The UI tests and unit tests on Views in iOS is very slick and has many benefits. Duplicating that here would work well and use the tools that we have to the best of their ability.
[ ] I still want some tests to be run on a physical device because I need to check screenshots to see if the visuals look good. Is there a way that I can annotate test methods with a specific annotation that then the Android UI tests pick up and only run those?
[ ] CI server, when running unit tests, also runs robolectric tests successfully.
Tests can be run with Robolectric for Android tests.
Todo:
sharedTests/
directory so Android can run tests and Robolectric can too.I am thinking that: Robolectric tests are great for unit tests. We test the UI of our code as unit tests (does X view exist?) kind of stuff. With this in mind, we want to decide to change the way we are running these tests (which will fix the problems we are currently facing). Instead of trying to use Teller initialization, for example, we save that only for the Android UI tests code that tests the UI with screenshots while we mock the ViewModel layer for robolectric unit tests?
This idea came from iOS where I write unit tests for the Views of the app and View controllers (fragments/activities essentially) and I mock the ViewModel for the unit tests just to test that certain views are shown and others are not. I concentrate my tests on just the 1 View class. True Android integration tests should run on the device because it's as close to the real thing as possible by running on the device. Also, we don't need to deal with the whole mess of robolectric. These tests can take screenshots, can test E2E fully, and can run on the device. Having this separation would be great for many benefits that I personally see when I do iOS dev. The UI tests and unit tests on Views in iOS is very slick and has many benefits. Duplicating that here would work well and use the tools that we have to the best of their ability.
Resources: