From 28dcdb7c3b9ce1d5d1f344b06c80847f8d165b5b Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Wed, 17 May 2017 15:37:03 -0700 Subject: [PATCH] Fix robolectric test failure Default UserManager caches instance across entire test suite, so test becomes flakey depending on the order they are run. Using a a ShadowUserManager without the cache ensures each test class gets a UserManager with clean state. Change-Id: Ia54f6a3259859add5a1e5d0101829497fb985ab1 Fix: 38393235 Test: make RunSettingsRoboTests --- .../settings/system/SystemDashboardFragmentTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java index 65b39e6facc..483dee7bc50 100644 --- a/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/system/SystemDashboardFragmentTest.java @@ -17,11 +17,13 @@ package com.android.settings.system; import android.content.Context; - import android.os.UserManager; + import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.testutils.XmlTestUtils; +import com.android.settings.testutils.shadow.ShadowUserManager; + import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; @@ -36,7 +38,10 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @RunWith(SettingsRobolectricTestRunner.class) -@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, + shadows = { + ShadowUserManager.class + }) public class SystemDashboardFragmentTest { @Test