Skip to content

Commit

Permalink
Implement acceptance tests for some basic features
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed May 31, 2017
1 parent 88c1e73 commit e4b5a3e
Show file tree
Hide file tree
Showing 19 changed files with 739 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ install_test_apk() {
run_instrumented_tests() {
log_info "Running instrumented tests"
$ADB shell am instrument \
-r -e coverage true \
-r -e coverage true -e size medium \
-w ${PACKAGE_NAME}.test/android.support.test.runner.AndroidJUnitRunner \
> ${OUTPUTS_DIR}/instrument.txt
| tee ${OUTPUTS_DIR}/instrument.txt

mkdir -p ${OUTPUTS_DIR}/code-coverage/connected/
$ADB pull /data/user/0/${PACKAGE_NAME}/files/coverage.ec \
Expand Down
1 change: 1 addition & 0 deletions uhabits-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
androidTestCompile 'com.linkedin.testbutler:test-butler-library:1.3.1'

implementation('com.opencsv:opencsv:3.9') {
Expand Down
27 changes: 27 additions & 0 deletions uhabits-android/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <[email protected]>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest
package="org.isoron.uhabits"
xmlns:android="http://schemas.android.com/apk/res/android">

<instrumentation>
<meta-data android:name="notPackage" android:value="net.bytebuddy"/>
</instrumentation>
</manifest>
Binary file added uhabits-android/src/androidTest/assets/test.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.os.*;
import android.support.annotation.*;
import android.support.test.*;
import android.support.test.filters.*;
import android.util.*;

import junit.framework.*;
Expand All @@ -44,6 +45,7 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;

@MediumTest
public class BaseAndroidTest extends TestCase
{
// 8:00am, January 25th, 2015 (UTC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,66 @@
package org.isoron.uhabits;

import android.content.*;
import android.support.test.filters.*;
import android.support.test.uiautomator.*;

import com.linkedin.android.testbutler.*;

import org.isoron.androidbase.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.preferences.*;
import org.isoron.uhabits.utils.*;
import org.junit.*;

import java.io.*;

import static android.support.test.InstrumentationRegistry.*;
import static android.support.test.uiautomator.UiDevice.*;

@LargeTest
public class BaseUIAutomatorTest
{
static final String PKG = "org.isoron.uhabits";
private static final String PKG = "org.isoron.uhabits";

public static UiDevice device;

protected UiDevice device;
private HabitsComponent component;

@Before
public void setUp()
public void setUp() throws IOException
{
TestButler.setup(getTargetContext());
TestButler.verifyAnimationsDisabled(getTargetContext());
device = getInstance(getInstrumentation());

HabitsComponent component = DaggerHabitsComponent
component = DaggerHabitsComponent
.builder()
.appModule(new AppModule(getTargetContext()))
.build();

AndroidPreferences prefs = component.getPreferences();
prefs.reset();
prefs.setFirstRun(false);

HabitsApplication.setComponent(component);

FileUtils.copy(getContext().getAssets().open("test.db"),
DatabaseUtils.getDatabaseFile(getTargetContext()));
}

@After
public void tearDown()
public void tearDown() throws Exception
{
device.pressHome();
device.waitForIdle();
TestButler.teardown(getTargetContext());
}

protected void startActivity(Class cls)
public static void startActivity(Class cls)
{
Intent intent = new Intent();
intent.setComponent(new ComponentName(PKG, cls.getCanonicalName()));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
getContext().startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.acceptance;

import org.isoron.uhabits.*;
import org.junit.*;

import static org.isoron.uhabits.acceptance.steps.CommonSteps.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*;

public class AboutTest extends BaseUIAutomatorTest
{
@Test
public void shouldDisplayAboutScreen()
{
launchApp();
clickMenu(ABOUT);
verifyDisplaysText("Loop Habit Tracker");
verifyDisplaysText("Rate this app on Google Play");
verifyDisplaysText("Developers");
verifyDisplaysText("Translators");

launchApp();
clickMenu(SETTINGS);
clickText("About");
verifyDisplaysText("Translators");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.acceptance;

import org.isoron.uhabits.*;
import org.junit.*;

import static org.isoron.uhabits.acceptance.steps.CommonSteps.*;
import static org.isoron.uhabits.acceptance.steps.EditHabitSteps.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*;

public class HabitsTest extends BaseUIAutomatorTest
{
@Test
public void shouldCreateHabit() throws Exception
{
launchApp();
clickMenu(CREATE_HABIT);
typeName("Hello world");
typeQuestion("Did you say hello to the world today?");
pickFrequency("Every week");
pickColor(5);
clickSave();
verifyDisplaysText("Hello world");
}

@Test
public void shouldShowHabitStatistics() throws Exception
{
launchApp();
clickText("Track time");
verifyDisplayGraphs();
}

@Test
public void shouldDeleteHabit() throws Exception
{
launchApp();
longClickText("Track time");
clickMenu(DELETE);
clickOK();
verifyDoesNotDisplayText("Track time");
}

@Test
public void shouldEditHabit() throws Exception
{
launchApp();
longClickText("Track time");
clickMenu(EDIT_HABIT);
typeName("Take a walk");
typeQuestion("Did you take a walk today?");
clickSave();
verifyDisplaysText("Take a walk");
verifyDoesNotDisplayText("Track time");
}

@Test
public void shouldEditHabit_fromStatisticsScreen() throws Exception
{
launchApp();
clickText("Track time");
clickMenu(EDIT_HABIT);
typeName("Take a walk");
typeQuestion("Did you take a walk today?");
pickColor(10);
clickSave();
verifyDisplaysText("Take a walk");
pressBack();
verifyDisplaysText("Take a walk");
verifyDoesNotDisplayText("Track time");
}

@Test
public void shouldArchiveAndUnarchiveHabits() throws Exception
{
launchApp();
longClickText("Track time");
clickMenu(ARCHIVE);
verifyDoesNotDisplayText("Track time");
clickMenu(HIDE_ARCHIVED);
verifyDisplaysText("Track time");

longClickText("Track time");
clickMenu(UNARCHIVE);
clickMenu(HIDE_ARCHIVED);
verifyDisplaysText("Track time");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.acceptance;

import org.isoron.uhabits.*;
import org.junit.*;

import static org.isoron.uhabits.acceptance.steps.CommonSteps.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.*;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.ABOUT;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.HELP;
import static org.isoron.uhabits.acceptance.steps.ListHabitsSteps.MenuItem.SETTINGS;

public class LinksTest extends BaseUIAutomatorTest
{
@Test
public void shouldLinkToSourceCode() throws Exception
{
launchApp();
clickMenu(ABOUT);
clickText("View source code at GitHub");
verifyOpensWebsite("https://github.com/iSoron/uhabits");
}

@Test
public void shouldLinkToTranslationWebsite() throws Exception
{
launchApp();
clickMenu(ABOUT);
clickText("Help translate this app");
verifyOpensWebsite("translate.loophabits.org");
}

@Test
public void shouldLinkToHelp() throws Exception
{
launchApp();
clickMenu(HELP);
verifyOpensWebsite("loophabits.org/faq.html");

launchApp();
clickMenu(SETTINGS);
clickText("Help & FAQ");
verifyOpensWebsite("loophabits.org/faq.html");
}
}
Loading

0 comments on commit e4b5a3e

Please sign in to comment.