Fix flakiness in MessagingAnalyticsRoboTest.java
Properly reset SharedPreferences test state in between each test.
@@ -105,6 +105,9 @@ public class MessagingAnalyticsRoboTest {
// Create and Initialize Firelog service components
context = ApplicationProvider.getApplicationContext();
+
+ // Reset sharedpreferences for bigquery delivery metrics export before every test.
+ resetPreferencesField(DELIVERY_METRICS_EXPORT_TO_BIG_QUERY_PREF);
}
/** If the developer didn't include Analytics and Firelog, we should not crash. */
@@ -331,6 +334,13 @@ public class MessagingAnalyticsRoboTest {
assertPreferencesFieldWithValue(DELIVERY_METRICS_EXPORT_TO_BIG_QUERY_PREF, true);
}
+ private void resetPreferencesField(String field) {
+ SharedPreferences preferences =
+ context.getSharedPreferences(FCM_PREFERENCES, Context.MODE_PRIVATE);
+
+ preferences.edit().remove(field).apply();
+ }
+
private void assertPreferencesFieldWithValue(String field, Boolean expectedValue) {
SharedPreferences preferences =
context.getSharedPreferences(FCM_PREFERENCES, Context.MODE_PRIVATE);
