Closed charliemangano closed 1 week ago
Instructions for Robolectric usage, copied from #208:
Usage
Write your androidTests as usual, in the androidTest package. Once your code is thoroughly tested and there is no need for debugging, add
@RunWith(RobolectricTestRunner::class)
as annotation to your test class. If you had another@RunWith
(most likely@RunWith(AndroidJUnit4::class)
), you can simply replace it with the new one.Now move the test files to the test sourceset (the unit test package), in the
ui
subpackage. For example, if you hadandroidTest/.../ui/profile/YourNewProfileScreenTest.kt
, you should now have nothing in your androidTest sourceset andtest/.../ui/profile/YourNewProfileScreenTest.kt
in your test sourceset. Now when running the tests, you won't need an emulator anymore.If you ever change something in the codebase that makes these tests not pass, you can move them back into the androidTest sourceset, get rid of the
RunWith
annotation and run them as usual to have the visual feedback of the emulator.
Description:
Running tests on an Android emulator or device is slow: building, deploying, and running the tests often take a while, so we want to add Robolectric to the project. It's a framework that would let us run our androidTests in a simulated Android environment inside a JVM, without the overhead and flakiness of an emulator.
Done: