- Prevent mocking ToggleScreenMagnificationPreferenceFragment for test - Use Robolectric's way to launch the fragment so that the fragment contains necessary setup **Root cause** - We called onCreateView directly in the test without the necessary setup in onCreate, which causes the FooterPreferenceController not being initialized. - We created a spyContext that returns a mock PackageManager, however, in the test execution, we didn't mock the context used by the fragment under test. Hence, the fragment didn't use the mock PackageManager in test. Bug: 284209879 Test: atest ToggleScreenMagnificationPreferenceFragmentTest --iterations 5 Change-Id: I7e71a03177526f5bb0c20a58855a7dfdffc2a22f
Running Settings Robolectric tests
The full suite
$ croot
$ make RunSettingsRoboTests
Running a single test class
$ croot
$ make RunSettingsRoboTests ROBOTEST_FILTER=<ClassName>
For example:
make RunSettingsRoboTests ROBOTEST_FILTER=CodeInspectionTest
You can also use partial class name in ROBOTEST_FILTER. If the partial class name matches multiple file names, all of them will be executed.