3

I am getting this error when I am trying to include the Fragment class.

Bound mismatch: The type FirstFragment is not a valid substitute for the bounded parameter of the type ActivityInstrumentationTestCase2

MY code is as under :

package com.example.firstactivity.test;

import com.example.firstactivity.FirstFragment;

import android.test.ActivityInstrumentationTestCase2;

public class TestFirstFragment extends ActivityInstrumentationTestCase2<FirstFragment> {

    private FirstFragment mFragment;

    public TestFirstFragment(Class activityClass) {
        super(activityClass);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mFragment = getActivity();
    }


    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public final void testPreconditions() {
        assertNotNull(mFragment);
    }

}

Please suggest a way to resolve this. When working with Activities it works fine... I have read some SO questions ex. FragmentActivity Junit Testing but either they did not answer my question or I could not follow them.

Community
  • 1
  • 1
dejavu
  • 91
  • 6

2 Answers2

0

In order to use ActivityInstrumentationTestCase2 like you are doing FirstFragment needs to extend Activity is some way. One of the fragment classes that does this is FragmentActivity. I'm assuming that you are using some other fragment class which is why you are getting the error.

DroidT
  • 3,168
  • 3
  • 31
  • 29
0

I was also having the same problem. It turns out that, the only class that you can substitute in place of the parameter "T" should extend "FragmentActivity". Or in my case the main class which is declared as "main" and "launcher" in the manifest.

zstart
  • 19
  • 2
  • 7