Android Test Orchestrator Runs several times the BeforeClass method. Since I'm using Espresso to do end-to-end testing, I'm calling some APIS to get some users created as a testsetup and they being created for every test, It's slowing down the test execution.
On gradle
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
...
androidTestUtil 'com.android.support.test:orchestrator:1.0.1'
public class LoginTest extends IntegrationTest {
@Rule
public ActivityTestRule<LoginActivity> activityTestRule = new ActivityTestRule<LoginActivity>(LoginActivity.class);
@BeforeClass
static public void doThisFirstOnlyOnce() {
Log.d("Testing_tag", "BEFORE CLASS");
}
@Before
public void doThisFirst() {
Log.d("Testing_tag", "BEFORE every test");
}
@After
public void doThisLast() {
Log.d("Testing_tag", "After every test");
}
@AfterClass
static public void doThisLastOnlyOnce() {
Log.d("Testing_tag", "AFTER CLASS");
}
@Test
public void test1() {
Log.d("Testing_tag", "Test 1");
}
@Test
public void test2() {
Log.d("Testing_tag", "Test 2");
}
}
I uses the same configuration for espresso and the rest.
Results
03-08 13:38:50.978 18756-18782/com.app D/Testing_tag: BEFORE CLASS
03-08 13:38:51.844 18756-18782/com.app D/Testing_tag: BEFORE every test
03-08 13:38:51.844 18756-18782/com.app D/Testing_tag: Test 1
03-08 13:38:51.844 18756-18782/com.app D/Testing_tag: After every test
03-08 13:38:52.141 18756-18782/com.app D/Testing_tag: AFTER CLASS
03-08 13:38:53.503 18825-18851/? D/Testing_tag: BEFORE CLASS
03-08 13:38:54.366 18825-18851/com.app D/Testing_tag: BEFORE every test
03-08 13:38:54.366 18825-18851/com.app D/Testing_tag: Test 2
03-08 13:38:54.366 18825-18851/com.app D/Testing_tag: After every test
03-08 13:38:54.728 18825-18851/com.app D/Testing_tag: AFTER CLASS
Do you know anyway to fix this?