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:
parent
0153766dd5
commit
4e964e271c
@ -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<WelcomeMessage> {
|
||||
|
||||
public A000_WelcomeAndSetupAccountIntegrationTest() {
|
||||
super(WelcomeMessage.class, false);
|
||||
}
|
||||
|
||||
public void testCreateAccount() throws Exception {
|
||||
new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage());
|
||||
}
|
||||
|
||||
public void testCreateSecondAccount() throws Exception {
|
||||
new AccountSetupFlow(this).setupAccountFromWelcomePage(new WelcomeMessagePage());
|
||||
@Test
|
||||
public void createAccount() throws Exception {
|
||||
new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSecondAccount() throws Exception {
|
||||
new AccountSetupFlow().setupAccountFromWelcomePage(new WelcomeMessagePage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Accounts>{
|
||||
|
||||
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);
|
||||
|
||||
|
@ -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<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
|
||||
|
||||
private ApplicationState state = ApplicationState.getInstance();
|
||||
private final boolean bypassWelcome;
|
||||
|
||||
public AbstractEndToEndTest(Class<T> activityClass) {
|
||||
@ -29,10 +34,22 @@ public abstract class AbstractEndToEndTest<T extends Activity> 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<T extends Activity> 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<T extends Activity> 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
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user