1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Convert to JUnit4 test

This commit is contained in:
Jan Berkel 2015-01-14 03:09:48 +01:00
parent 0153766dd5
commit 4e964e271c
4 changed files with 63 additions and 28 deletions

View File

@ -1,24 +1,32 @@
package com.fsck.k9.endtoend; package com.fsck.k9.endtoend;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.activity.setup.WelcomeMessage; import com.fsck.k9.activity.setup.WelcomeMessage;
import com.fsck.k9.endtoend.framework.ApplicationState;
import com.fsck.k9.endtoend.pages.WelcomeMessagePage; import com.fsck.k9.endtoend.pages.WelcomeMessagePage;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Creates a new IMAP account via the getting started flow. * Creates a new IMAP account via the getting started flow.
*/ */
@RunWith(AndroidJUnit4.class)
public class A000_WelcomeAndSetupAccountIntegrationTest extends AbstractEndToEndTest<WelcomeMessage> { public class A000_WelcomeAndSetupAccountIntegrationTest extends AbstractEndToEndTest<WelcomeMessage> {
public A000_WelcomeAndSetupAccountIntegrationTest() { public A000_WelcomeAndSetupAccountIntegrationTest() {
super(WelcomeMessage.class, false); super(WelcomeMessage.class, false);
} }
public void testCreateAccount() throws Exception { @Test
new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage()); public void createAccount() throws Exception {
new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage());
} }
public void testCreateSecondAccount() throws Exception { @Test
new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage()); public void createSecondAccount() throws Exception {
new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage());
} }
} }

View File

@ -1,9 +1,14 @@
package com.fsck.k9.endtoend; package com.fsck.k9.endtoend;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.activity.Accounts; import com.fsck.k9.activity.Accounts;
import com.fsck.k9.endtoend.framework.AccountForTest; import com.fsck.k9.endtoend.framework.AccountForTest;
import com.fsck.k9.endtoend.framework.ApplicationState; import com.fsck.k9.endtoend.framework.ApplicationState;
import com.fsck.k9.endtoend.pages.AccountsPage; import com.fsck.k9.endtoend.pages.AccountsPage;
import org.junit.Test;
import org.junit.runner.RunWith;
/** /**
* Creates and removes accounts. * Creates and removes accounts.
@ -11,20 +16,26 @@ import com.fsck.k9.endtoend.pages.AccountsPage;
* Because of the way K-9 shows the start page, there must already be two accounts * Because of the way K-9 shows the start page, there must already be two accounts
* in existence for this test to work. * in existence for this test to work.
*/ */
@RunWith(AndroidJUnit4.class)
public class A010_AccountIntegrationTest extends AbstractEndToEndTest<Accounts>{ public class A010_AccountIntegrationTest extends AbstractEndToEndTest<Accounts>{
public A010_AccountIntegrationTest() { public A010_AccountIntegrationTest() {
super(Accounts.class); super(Accounts.class);
} }
public void testCreateAccountDirectly() throws Exception { @Test
new AccountSetupFlow(this).setupAccountFromAccountsPage(new AccountsPage()); public void createAccountDirectly() throws Exception {
new AccountSetupFlow().setupAccountFromAccountsPage(new AccountsPage());
} }
public void testDeleteAccount() { @Test
public void deleteAccount() {
AccountsPage accountsPage = new AccountsPage(); AccountsPage accountsPage = new AccountsPage();
// TODO should not have cross-test-dependencies
assertFalse("NB: this test is order dependent and requires A000_WelcomeAndSetupAccountIntegrationTest to run first",
ApplicationState.getInstance().accounts.isEmpty());
AccountForTest accountForTest = ApplicationState.getInstance().accounts.get(0); AccountForTest accountForTest = ApplicationState.getInstance().accounts.get(0);
accountsPage.assertAccountExists(accountForTest.description); accountsPage.assertAccountExists(accountForTest.description);

View File

@ -1,6 +1,9 @@
package com.fsck.k9.endtoend; package com.fsck.k9.endtoend;
import android.app.Activity; import android.app.Activity;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.assertion.ViewAssertions;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.util.Log; import android.util.Log;
@ -8,16 +11,18 @@ import com.fsck.k9.R;
import com.fsck.k9.endtoend.framework.ApplicationState; import com.fsck.k9.endtoend.framework.ApplicationState;
import com.fsck.k9.endtoend.framework.StubMailServer; import com.fsck.k9.endtoend.framework.StubMailServer;
import com.fsck.k9.endtoend.pages.WelcomeMessagePage; import com.fsck.k9.endtoend.pages.WelcomeMessagePage;
import android.support.test.espresso.assertion.ViewAssertions;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
@RunWith(AndroidJUnit4.class)
public abstract class AbstractEndToEndTest<T extends Activity> extends ActivityInstrumentationTestCase2<T> { public abstract class AbstractEndToEndTest<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
private ApplicationState state = ApplicationState.getInstance();
private final boolean bypassWelcome; private final boolean bypassWelcome;
public AbstractEndToEndTest(Class<T> activityClass) { public AbstractEndToEndTest(Class<T> activityClass) {
@ -29,10 +34,22 @@ public abstract class AbstractEndToEndTest<T extends Activity> extends ActivityI
this.bypassWelcome = bypassWelcome; this.bypassWelcome = bypassWelcome;
} }
@BeforeClass
public static void beforeClass() {
ApplicationState.getInstance().stubMailServer = new StubMailServer();
}
@AfterClass
public static void afterClass() {
ApplicationState.getInstance().stubMailServer.stop();
}
@Before
@Override @Override
protected void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
state.stubMailServer = new StubMailServer(); injectInstrumentation(InstrumentationRegistry.getInstrumentation());
getActivity(); getActivity();
if (bypassWelcome) { if (bypassWelcome) {
@ -40,9 +57,10 @@ public abstract class AbstractEndToEndTest<T extends Activity> extends ActivityI
} }
} }
@After
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
state.stubMailServer.stop(); super.tearDown();
} }
private void bypassWelcomeScreen() { private void bypassWelcomeScreen() {
@ -53,11 +71,12 @@ public abstract class AbstractEndToEndTest<T extends Activity> extends ActivityI
* The view doesn't NOT exist == the view exists, and needs to be bypassed! * The view doesn't NOT exist == the view exists, and needs to be bypassed!
*/ */
Log.d(getClass().getName(), "Bypassing welcome"); Log.d(getClass().getName(), "Bypassing welcome");
new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage()); new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage());
} }
} }
public StubMailServer stubMailServer() {
return state.stubMailServer; public void testEmpty() {
// workaround, needs to be empty so that JUnit4 test gets picked up
} }
} }

View File

@ -24,12 +24,6 @@ public class AccountSetupFlow {
static final String ACCOUNT_NAME = "sendAndReceiveTestName"; static final String ACCOUNT_NAME = "sendAndReceiveTestName";
private final AbstractEndToEndTest test;
public AccountSetupFlow(AbstractEndToEndTest test) {
this.test = test;
}
public AccountsPage setupAccountFromWelcomePage(WelcomeMessagePage welcomeMessagePage) { public AccountsPage setupAccountFromWelcomePage(WelcomeMessagePage welcomeMessagePage) {
AccountSetupPage accountSetupPage = welcomeMessagePage.clickNext(); AccountSetupPage accountSetupPage = welcomeMessagePage.clickNext();
return setupAccountFromSetupNewAccountActivity(accountSetupPage); return setupAccountFromSetupNewAccountActivity(accountSetupPage);
@ -45,9 +39,12 @@ public class AccountSetupFlow {
IncomingServerSettingsPage incoming = accountTypePage.clickImap(); IncomingServerSettingsPage incoming = accountTypePage.clickImap();
OutgoingServerSettingsPage outgoing = setupIncomingServerAndClickNext(incoming, test.stubMailServer());
AccountOptionsPage accountOptionsPage = setupOutgoingServerAndClickNext(outgoing, test.stubMailServer()); StubMailServer stubMailServer = ApplicationState.getInstance().stubMailServer;
OutgoingServerSettingsPage outgoing = setupIncomingServerAndClickNext(incoming, stubMailServer);
AccountOptionsPage accountOptionsPage = setupOutgoingServerAndClickNext(outgoing, stubMailServer);
AccountSetupNamesPage accountSetupNamesPage = accountOptionsPage.clickNext(); AccountSetupNamesPage accountSetupNamesPage = accountOptionsPage.clickNext();
@ -59,7 +56,7 @@ public class AccountSetupFlow {
accountsPage.assertAccountExists(accountDescription); accountsPage.assertAccountExists(accountDescription);
ApplicationState.getInstance().accounts.add(new AccountForTest(ACCOUNT_NAME, accountDescription, test.stubMailServer())); ApplicationState.getInstance().accounts.add(new AccountForTest(ACCOUNT_NAME, accountDescription, stubMailServer));
return accountsPage; return accountsPage;
} }