fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTests.java
@Test
    public void removeHiddenView() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        ViewGroup container = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment1 = new StrictViewFragment();
        fm.beginTransaction().add(R.id.fragmentContainer, fragment1, "1").hide(fragment1).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container, fragment1);
        assertTrue(fragment1.isHidden());

        fm.beginTransaction().remove(fragment1).addToBackStack(null).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container);

        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        final Fragment replacement1 = fm.findFragmentByTag("1");
        FragmentTestUtil.assertChildren(container, replacement1);
        assertTrue(replacement1.isHidden());
        assertEquals(View.GONE, replacement1.getView().getVisibility());
    }
// Removing a hidden fragment should remove the View and popping should bring it back hidden
Removing a hidden fragment should remove the View and popping should bring it back hidden
Removing a hidden fragment should remove the View and popping should bring it back hidden
@Test
    public void removeHiddenView() throws Throwable {
        FragmentTestUtil.setContentView(mActivityRule, R.layout.simple_container);
        ViewGroup container = (ViewGroup)
                mActivityRule.getActivity().findViewById(R.id.fragmentContainer);
        final FragmentManager fm = mActivityRule.getActivity().getSupportFragmentManager();
        final StrictViewFragment fragment1 = new StrictViewFragment();
        fm.beginTransaction().add(R.id.fragmentContainer, fragment1, "1").hide(fragment1).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container, fragment1);
        assertTrue(fragment1.isHidden());
        fm.beginTransaction().remove(fragment1).addToBackStack(null).commit();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        FragmentTestUtil.assertChildren(container);
        fm.popBackStack();
        FragmentTestUtil.executePendingTransactions(mActivityRule);
        final Fragment replacement1 = fm.findFragmentByTag("1");
        FragmentTestUtil.assertChildren(container, replacement1);
        assertTrue(replacement1.isHidden());
        assertEquals(View.GONE, replacement1.getView().getVisibility());
    }
@ Test public void removeHiddenView ( ) throws Throwable { FragmentTestUtil . setContentView ( mActivityRule , R . layout . simple_container ) ; ViewGroup container = ( ViewGroup ) mActivityRule . getActivity ( ) . findViewById ( R . id . fragmentContainer ) ; final FragmentManager fm = mActivityRule . getActivity ( ) . getSupportFragmentManager ( ) ; final StrictViewFragment fragment1 = new StrictViewFragment ( ) ; fm . beginTransaction ( ) . add ( R . id . fragmentContainer , fragment1 , "1" ) . hide ( fragment1 ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; FragmentTestUtil . assertChildren ( container , fragment1 ) ; assertTrue ( fragment1 . isHidden ( ) ) ; fm . beginTransaction ( ) . remove ( fragment1 ) . addToBackStack ( null ) . commit ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; FragmentTestUtil . assertChildren ( container ) ; fm . popBackStack ( ) ; FragmentTestUtil . executePendingTransactions ( mActivityRule ) ; final Fragment replacement1 = fm . findFragmentByTag ( "1" ) ; FragmentTestUtil . assertChildren ( container , replacement1 ) ; assertTrue ( replacement1 . isHidden ( ) ) ; assertEquals ( View . GONE , replacement1 . getView ( ) . getVisibility ( ) ) ; }
Removing a hidden fragment should remove the View and popping should bring it back hidden
Removing a hidden fragment should remove the View and popping should bring it back hidden