From 4e964e271c865d58bdf5bc402aebd2887998f78c Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Wed, 14 Jan 2015 03:09:48 +0100 Subject: [PATCH] Convert to JUnit4 test --- ...WelcomeAndSetupAccountIntegrationTest.java | 18 ++++++--- .../endtoend/A010_AccountIntegrationTest.java | 19 +++++++-- .../k9/endtoend/AbstractEndToEndTest.java | 39 ++++++++++++++----- .../fsck/k9/endtoend/AccountSetupFlow.java | 15 +++---- 4 files changed, 63 insertions(+), 28 deletions(-) diff --git a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A000_WelcomeAndSetupAccountIntegrationTest.java b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A000_WelcomeAndSetupAccountIntegrationTest.java index c6a9187dc..73cf51eb7 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A000_WelcomeAndSetupAccountIntegrationTest.java +++ b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A000_WelcomeAndSetupAccountIntegrationTest.java @@ -1,24 +1,32 @@ package com.fsck.k9.endtoend; +import android.support.test.runner.AndroidJUnit4; + import com.fsck.k9.activity.setup.WelcomeMessage; +import com.fsck.k9.endtoend.framework.ApplicationState; 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. */ +@RunWith(AndroidJUnit4.class) public class A000_WelcomeAndSetupAccountIntegrationTest extends AbstractEndToEndTest { public A000_WelcomeAndSetupAccountIntegrationTest() { super(WelcomeMessage.class, false); } - public void testCreateAccount() throws Exception { - new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage()); + @Test + public void createAccount() throws Exception { + new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage()); } - public void testCreateSecondAccount() throws Exception { - new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage()); + @Test + public void createSecondAccount() throws Exception { + new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage()); } - } diff --git a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A010_AccountIntegrationTest.java b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A010_AccountIntegrationTest.java index d3fc8701c..59cb41f44 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A010_AccountIntegrationTest.java +++ b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/A010_AccountIntegrationTest.java @@ -1,9 +1,14 @@ package com.fsck.k9.endtoend; +import android.support.test.runner.AndroidJUnit4; + import com.fsck.k9.activity.Accounts; import com.fsck.k9.endtoend.framework.AccountForTest; import com.fsck.k9.endtoend.framework.ApplicationState; import com.fsck.k9.endtoend.pages.AccountsPage; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * 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 * in existence for this test to work. */ +@RunWith(AndroidJUnit4.class) public class A010_AccountIntegrationTest extends AbstractEndToEndTest{ public A010_AccountIntegrationTest() { super(Accounts.class); } - public void testCreateAccountDirectly() throws Exception { - new AccountSetupFlow(this).setupAccountFromAccountsPage(new AccountsPage()); + @Test + public void createAccountDirectly() throws Exception { + new AccountSetupFlow().setupAccountFromAccountsPage(new AccountsPage()); } - public void testDeleteAccount() { - + @Test + public void deleteAccount() { 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); accountsPage.assertAccountExists(accountForTest.description); diff --git a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AbstractEndToEndTest.java b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AbstractEndToEndTest.java index 0db1b97b5..681ad25b6 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AbstractEndToEndTest.java +++ b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AbstractEndToEndTest.java @@ -1,6 +1,9 @@ package com.fsck.k9.endtoend; 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.util.Log; @@ -8,16 +11,18 @@ import com.fsck.k9.R; import com.fsck.k9.endtoend.framework.ApplicationState; import com.fsck.k9.endtoend.framework.StubMailServer; import com.fsck.k9.endtoend.pages.WelcomeMessagePage; -import android.support.test.espresso.assertion.ViewAssertions; - 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.matcher.ViewMatchers.withId; +@RunWith(AndroidJUnit4.class) public abstract class AbstractEndToEndTest extends ActivityInstrumentationTestCase2 { - - private ApplicationState state = ApplicationState.getInstance(); private final boolean bypassWelcome; public AbstractEndToEndTest(Class activityClass) { @@ -29,10 +34,22 @@ public abstract class AbstractEndToEndTest extends ActivityI this.bypassWelcome = bypassWelcome; } + @BeforeClass + public static void beforeClass() { + ApplicationState.getInstance().stubMailServer = new StubMailServer(); + } + + @AfterClass + public static void afterClass() { + ApplicationState.getInstance().stubMailServer.stop(); + } + + @Before @Override - protected void setUp() throws Exception { + public void setUp() throws Exception { super.setUp(); - state.stubMailServer = new StubMailServer(); + injectInstrumentation(InstrumentationRegistry.getInstrumentation()); + getActivity(); if (bypassWelcome) { @@ -40,9 +57,10 @@ public abstract class AbstractEndToEndTest extends ActivityI } } + @After @Override public void tearDown() throws Exception { - state.stubMailServer.stop(); + super.tearDown(); } private void bypassWelcomeScreen() { @@ -53,11 +71,12 @@ public abstract class AbstractEndToEndTest extends ActivityI * The view doesn't NOT exist == the view exists, and needs to be bypassed! */ 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 } } diff --git a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AccountSetupFlow.java b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AccountSetupFlow.java index cdd087704..af83737f1 100644 --- a/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AccountSetupFlow.java +++ b/k9mail/src/androidTest/java/com/fsck/k9/endtoend/AccountSetupFlow.java @@ -24,12 +24,6 @@ public class AccountSetupFlow { static final String ACCOUNT_NAME = "sendAndReceiveTestName"; - private final AbstractEndToEndTest test; - - public AccountSetupFlow(AbstractEndToEndTest test) { - this.test = test; - } - public AccountsPage setupAccountFromWelcomePage(WelcomeMessagePage welcomeMessagePage) { AccountSetupPage accountSetupPage = welcomeMessagePage.clickNext(); return setupAccountFromSetupNewAccountActivity(accountSetupPage); @@ -45,9 +39,12 @@ public class AccountSetupFlow { 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(); @@ -59,7 +56,7 @@ public class AccountSetupFlow { 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; }