Skip to content

Commit 5aa2678

Browse files
committed
Fix DevMenuMainViewInstrumentationTest
1 parent fce8c86 commit 5aa2678

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/src/androidTest/java/com/amplifyframework/devmenu/DevMenuMainViewInstrumentationTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.junit.Before;
3030
import org.junit.Test;
3131

32+
import java.util.concurrent.CountDownLatch;
33+
3234
import static androidx.test.espresso.Espresso.onView;
3335
import static org.junit.Assert.assertEquals;
3436
import static org.junit.Assert.assertNotNull;
@@ -38,20 +40,24 @@
3840
*/
3941
public final class DevMenuMainViewInstrumentationTest {
4042
// A navigation host controller for testing.
41-
private TestNavHostController navHostController;
43+
private volatile TestNavHostController navHostController;
4244

4345
/**
4446
* Go to the main screen of the developer menu.
47+
* @throws Exception if fragment doesn't attach
4548
*/
4649
@Before
47-
public void resetView() {
50+
public void resetView() throws Exception {
51+
CountDownLatch latch = new CountDownLatch(1);
4852
FragmentScenario<DevMenuMainFragment> mainMenuScenario =
4953
FragmentScenario.launchInContainer(DevMenuMainFragment.class);
5054
mainMenuScenario.onFragment(fragment -> {
5155
navHostController = new TestNavHostController(ApplicationProvider.getApplicationContext());
5256
navHostController.setGraph(R.navigation.dev_menu_nav_graph);
5357
Navigation.setViewNavController(fragment.requireView(), navHostController);
58+
latch.countDown();
5459
});
60+
latch.await();
5561
}
5662

5763

0 commit comments

Comments
 (0)