title: java.lang.IllegalStateException: Activity has been destroyed
body: <p>Working with Robolectric , I'm very new to android. I made a first test class using Activity. It worked nicely.
  Now I want make a test for fragment.</p>
  
  <pre><code>@RunWith(RobolectricTestRunner.class)
  public class LoginFragmentTest {
      private LoginFragment fragment;
  
      @Before
      public void setup() {
          fragment = new LoginFragment();
          startFragment(fragment);
          assertThat(fragment, notNullValue());
          assertThat(fragment.getActivity(), notNullValue());
      }
  
      private void startFragment(LoginFragment fragment) {
          FragmentManager fragmentManager = new FragmentActivity().getSupportFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.add(fragment, null);
          fragmentTransaction.commit();
      }
  
      @Test
      public void login() {
          EditText idEditText = (EditText)fragment.getActivity().findViewById(R.id.main_id);
          assertThat(idEditText, notNullValue());
      }
  }
  </code></pre>
  
  <p>This is my first test class for Fragment class. It throws </p>
  
  <pre><code>"java.lang.IllegalStateException: Activity has been destroyed" in startFragment#fragmentTransaction.commit().
  </code></pre>
  
  <p>Anyone knows how to fix this ?</p>
  
  <p>You can find whole source from <a href="https://github.com/msbaek/frame-test" rel="nofollow">https://github.com/msbaek/frame-test</a></p>
  
  <p>Thanks in advance !!</p>