Skip to content

Commit

Permalink
Split testing into two steps - unit and UX tests
Browse files Browse the repository at this point in the history
Modified account delete test to be a simple test
  • Loading branch information
codinguser committed May 21, 2015
1 parent da27b31 commit 719e53e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ before_script:
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window -no-boot-anim -sdcard sdcard/gnucash-sdcard.img &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- adb shell input keyevent 82 &

script:
- ./gradlew build
- ./gradlew connectedCheck
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
import org.gnucash.android.receivers.AccountCreator;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.account.AccountsListFragment;
Expand All @@ -60,7 +58,6 @@
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.android.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -98,6 +95,7 @@ public void setUp() throws Exception {
mSplitsDbAdapter = new SplitsDbAdapter(mDb);
mTransactionsDbAdapter = new TransactionsDbAdapter(mDb, mSplitsDbAdapter);
mAccountsDbAdapter = new AccountsDbAdapter(mDb, mTransactionsDbAdapter);
mAccountsDbAdapter.deleteAllRecords(); //clear the data

Account account = new Account(DUMMY_ACCOUNT_NAME);
account.setUID(DUMMY_ACCOUNT_UID);
Expand Down Expand Up @@ -218,8 +216,8 @@ public void testChangeParentAccount() {
@Test
public void testEditAccount(){
String editedAccountName = "Edited Account";
// onView(withText(DUMMY_ACCOUNT_NAME)).perform(longClick());
onView(withId(R.id.primary_text)).perform(longClick());
sleep(2000);
onView(withId(R.id.primary_text)).perform(longClick());
onView(withId(R.id.context_menu_edit_accounts)).perform(click());

onView(withId(R.id.fragment_account_form)).check(matches(isDisplayed()));
Expand All @@ -235,28 +233,34 @@ public void testEditAccount(){
assertThat(latest.getCurrency().getCurrencyCode()).isEqualTo(DUMMY_ACCOUNT_CURRENCY_CODE);
}

/**
* Sleep the thread for a specified period
* @param millis Duration to sleep in milliseconds
*/
private void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

//TODO: Add test for moving content of accounts before deleting it
@Test(expected = IllegalArgumentException.class)
public void testDeleteAccount() {
Transaction transaction = new Transaction("hats");
transaction.addSplit(new Split(Money.getZeroInstance(), DUMMY_ACCOUNT_UID));
mTransactionsDbAdapter.addTransaction(transaction);

onView(withText(DUMMY_ACCOUNT_NAME)).perform(longClick());
public void testDeleteSimpleAccount() {
sleep(2000);
onView(withId(R.id.primary_text)).perform(longClick());
onView(withId(R.id.context_menu_delete)).perform(click());

//the account has no sub-accounts
onView(withId(R.id.accounts_options)).check(matches(not(isDisplayed())));
onView(withId(R.id.transactions_options)).check(matches(isDisplayed()));
// onView(withId(R.id.accounts_options)).check(matches(not(isDisplayed())));
// onView(withId(R.id.transactions_options)).check(matches(isDisplayed()));

onView(withText(R.string.label_delete_transactions)).perform(click());
onView(withId(R.id.btn_save)).perform(click());
// onView(withText(R.string.label_delete_transactions)).perform(click());
// onView(withId(R.id.btn_save)).perform(click());

//should throw expected exception
mAccountsDbAdapter.getID(DUMMY_ACCOUNT_UID);

List<Transaction> transactions = mTransactionsDbAdapter.getAllTransactionsForAccount(DUMMY_ACCOUNT_UID);
assertThat(transactions).isEmpty();
mAccountsDbAdapter.getID(DUMMY_ACCOUNT_UID);;
}

//TODO: Test import of account file
Expand All @@ -281,8 +285,6 @@ public void testIntentAccountCreation(){
@After
public void tearDown() throws Exception {
mAcccountsActivity.finish();
Thread.sleep(1000);
mAccountsDbAdapter.deleteAllRecords(); //clear the data
super.tearDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void setUp() throws Exception {
mSplitsDbAdapter = new SplitsDbAdapter(mDb);
mTransactionsDbAdapter = new TransactionsDbAdapter(mDb, mSplitsDbAdapter);
mAccountsDbAdapter = new AccountsDbAdapter(mDb, mTransactionsDbAdapter);
mAccountsDbAdapter.deleteAllRecords();

mTransactionTimeMillis = System.currentTimeMillis();
Account account = new Account(DUMMY_ACCOUNT_NAME);
Expand Down Expand Up @@ -540,8 +541,6 @@ private void clickOnView(int viewId){
@After
public void tearDown() throws Exception {
mTransactionsActivity.finish();
Thread.sleep(1000);
mAccountsDbAdapter.deleteAllRecords();
super.tearDown();
}
}

0 comments on commit 719e53e

Please sign in to comment.