Skip to content

Instantly share code, notes, and snippets.

@lparoli
Created May 4, 2015 06:53
Show Gist options
  • Select an option

  • Save lparoli/413e186b34512997346e to your computer and use it in GitHub Desktop.

Select an option

Save lparoli/413e186b34512997346e to your computer and use it in GitHub Desktop.
Base class for your Espresso tests, using JUnit4.
package qa.com.espressospoonstructure.tests;
import android.app.Activity;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public abstract class BaseTestCase<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
protected BaseTestCase(Class<T> activityUnderTest) {
super(activityUnderTest);
}
@Before
public void setUp() throws Exception {
super.setUp();
//Required by JUnit4
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
//Launches your activity
Activity activity = getActivity();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment