Merge pull request #2870 from ByteHamster/tests-fix

Updated tests
This commit is contained in:
Martin Fietz 2018-11-11 11:01:24 +01:00 committed by GitHub
commit 68b245701e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 282 additions and 219 deletions

View File

@ -43,7 +43,7 @@ android {
versionCode getMyVersionCode()
versionName "${getMyVersionName()}"
testApplicationId "de.test.antennapod"
testInstrumentationRunner "de.test.antennapod.AntennaPodTestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
generatedDensities = []
}
@ -120,6 +120,10 @@ android {
additionalParameters "--no-version-vectors"
}
testOptions {
animationsDisabled = true
}
flavorDimensions "market"
productFlavors {
free {
@ -184,6 +188,11 @@ dependencies {
implementation 'com.github.ByteHamster:SearchPreference:v1.0.8'
androidTestImplementation "com.jayway.android.robotium:robotium-solo:$robotiumSoloVersion"
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
play {

View File

@ -1,18 +0,0 @@
package de.test.antennapod;
import android.test.InstrumentationTestRunner;
import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.TestSuite;
public class AntennaPodTestRunner extends InstrumentationTestRunner {
@Override
public TestSuite getAllTests() {
return new TestSuiteBuilder(AntennaPodTestRunner.class)
.includeAllPackagesUnderHere()
.excludePackages("de.test.antennapod.gpodnet")
.build();
}
}

View File

@ -0,0 +1,38 @@
package de.test.antennapod;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import java.util.concurrent.atomic.AtomicInteger;
public class NthMatcher {
public static <T> Matcher<T> first(final Matcher<T> matcher) {
return nth(matcher, 1);
}
public static <T> Matcher<T> second(final Matcher<T> matcher) {
return nth(matcher, 2);
}
private static <T> Matcher<T> nth(final Matcher<T> matcher, final int index) {
return new BaseMatcher<T>() {
AtomicInteger count = new AtomicInteger(0);
@Override
public boolean matches(final Object item) {
if (matcher.matches(item)) {
if (count.incrementAndGet() == index) {
return true;
}
}
return false;
}
@Override
public void describeTo(final Description description) {
description.appendText("should return first matching item");
}
};
}
}

View File

@ -1,43 +1,43 @@
package de.test.antennapod.gpodnet;
import android.test.AndroidTestCase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.support.test.runner.AndroidJUnit4;
import de.danoeh.antennapod.core.gpoddernet.GpodnetService;
import de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetDevice;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static java.util.Collections.singletonList;
/**
* Test class for GpodnetService
*/
public class GPodnetServiceTest extends AndroidTestCase {
@Ignore
@RunWith(AndroidJUnit4.class)
public class GPodnetServiceTest {
private GpodnetService service;
private static final String USER = "";
private static final String PW = "";
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
protected void setUp() {
service = new GpodnetService();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
private void authenticate() throws GpodnetServiceException {
service.authenticate(USER, PW);
}
@Test
public void testUploadSubscription() throws GpodnetServiceException {
authenticate();
ArrayList<String> l = new ArrayList<>();
@ -45,6 +45,7 @@ public class GPodnetServiceTest extends AndroidTestCase {
service.uploadSubscriptions(USER, "radio", l);
}
@Test
public void testUploadSubscription2() throws GpodnetServiceException {
authenticate();
ArrayList<String> l = new ArrayList<>();
@ -53,6 +54,7 @@ public class GPodnetServiceTest extends AndroidTestCase {
service.uploadSubscriptions(USER, "radio", l);
}
@Test
public void testUploadChanges() throws GpodnetServiceException {
authenticate();
String[] URLS = {"http://bitsundso.de/feed", "http://gamesundso.de/feed", "http://cre.fm/feed/mp3/", "http://freakshow.fm/feed/m4a/"};
@ -63,53 +65,63 @@ public class GPodnetServiceTest extends AndroidTestCase {
service.uploadChanges(USER, "radio", added, removed);
}
@Test
public void testGetSubscriptionChanges() throws GpodnetServiceException {
authenticate();
service.getSubscriptionChanges(USER, "radio", 1362322610L);
}
@Test
public void testGetSubscriptionsOfUser()
throws GpodnetServiceException {
authenticate();
service.getSubscriptionsOfUser(USER);
}
@Test
public void testGetSubscriptionsOfDevice()
throws GpodnetServiceException {
authenticate();
service.getSubscriptionsOfDevice(USER, "radio");
}
@Test
public void testConfigureDevices() throws GpodnetServiceException {
authenticate();
service.configureDevice(USER, "foo", "This is an updated caption",
GpodnetDevice.DeviceType.LAPTOP);
}
@Test
public void testGetDevices() throws GpodnetServiceException {
authenticate();
service.getDevices(USER);
}
@Test
public void testGetSuggestions() throws GpodnetServiceException {
authenticate();
service.getSuggestions(10);
}
@Test
public void testTags() throws GpodnetServiceException {
service.getTopTags(20);
}
@Test
public void testPodcastForTags() throws GpodnetServiceException {
List<GpodnetTag> tags = service.getTopTags(20);
service.getPodcastsForTag(tags.get(1),
10);
}
@Test
public void testSearch() throws GpodnetServiceException {
service.searchPodcasts("linux", 64);
}
@Test
public void testToplist() throws GpodnetServiceException {
service.getPodcastToplist(10);
}

View File

@ -2,16 +2,14 @@ package de.test.antennapod.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.test.ActivityInstrumentationTestCase2;
import android.test.FlakyTest;
import android.support.test.espresso.contrib.DrawerActions;
import android.support.test.espresso.intent.Intents;
import android.support.test.filters.FlakyTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.ListView;
import com.robotium.solo.Solo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.robotium.solo.Timeout;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
@ -23,25 +21,46 @@ import de.danoeh.antennapod.fragment.DownloadsFragment;
import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
import de.danoeh.antennapod.fragment.QueueFragment;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static de.test.antennapod.NthMatcher.first;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
/**
* User interface tests for MainActivity
*/
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
private Solo solo;
private UITestUtils uiTestUtils;
private SharedPreferences prefs;
public MainActivityTest() {
super(MainActivity.class);
}
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Override
protected void setUp() throws Exception {
super.setUp();
Context context = getInstrumentation().getTargetContext();
@Before
public void setUp() throws IOException {
Intents.init();
Context context = mActivityRule.getActivity();
uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
@ -54,30 +73,26 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
// override first launch preference
// do this BEFORE calling getActivity()!
prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
prefs = context.getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
solo = new Solo(getInstrumentation(), getActivity());
solo = new Solo(getInstrumentation(), mActivityRule.getActivity());
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
uiTestUtils.tearDown();
solo.finishOpenedActivities();
Intents.release();
PodDBAdapter.deleteDatabase();
// reset preferences
prefs.edit().clear().commit();
super.tearDown();
}
private void openNavDrawer() {
solo.clickOnImageButton(0);
getInstrumentation().waitForIdleSync();
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
}
@Test
public void testAddFeed() throws Exception {
uiTestUtils.addHostedFeedData();
final Feed feed = uiTestUtils.hostedFeeds.get(0);
@ -89,10 +104,12 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
solo.waitForView(R.id.butSubscribe);
assertEquals(solo.getString(R.string.subscribe_label), solo.getButton(0).getText().toString());
solo.clickOnButton(0);
solo.waitForText(solo.getString(R.string.subscribed_label));
assertTrue(solo.waitForText(solo.getString(R.string.open_podcast), 0, Timeout.getLargeTimeout(), false));
}
@FlakyTest(tolerance = 3)
@Test
@FlakyTest
public void testClickNavDrawer() throws Exception {
uiTestUtils.addLocalFeedData(false);
@ -150,57 +167,60 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
return ((MainActivity) solo.getCurrentActivity()).getSupportActionBar().getTitle().toString();
}
@SuppressWarnings("unchecked")
@FlakyTest(tolerance = 3)
@Test
@FlakyTest
public void testGoToPreferences() {
openNavDrawer();
solo.clickOnText(solo.getString(R.string.settings_label));
solo.waitForActivity(PreferenceActivity.class);
onView(withText(R.string.settings_label)).perform(click());
intended(hasComponent(PreferenceActivity.class.getName()));
}
@Test
public void testDrawerPreferencesHideSomeElements() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
openNavDrawer();
solo.clickLongOnText(solo.getString(R.string.queue_label));
solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(R.string.episodes_label));
solo.clickOnText(solo.getString(R.string.playback_history_label));
solo.clickOnText(solo.getString(R.string.confirm_label));
solo.waitForDialogToClose();
onView(first(withText(R.string.queue_label))).perform(longClick());
onView(withText(R.string.episodes_label)).perform(click());
onView(withText(R.string.playback_history_label)).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
List<String> hidden = UserPreferences.getHiddenDrawerItems();
assertEquals(2, hidden.size());
assertTrue(hidden.contains(EpisodesFragment.TAG));
assertTrue(hidden.contains(PlaybackHistoryFragment.TAG));
}
@Test
public void testDrawerPreferencesUnhideSomeElements() {
List<String> hidden = Arrays.asList(PlaybackHistoryFragment.TAG, DownloadsFragment.TAG);
UserPreferences.setHiddenDrawerItems(hidden);
openNavDrawer();
solo.clickLongOnText(solo.getString(R.string.queue_label));
solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(R.string.downloads_label));
solo.clickOnText(solo.getString(R.string.queue_label));
solo.clickOnText(solo.getString(R.string.confirm_label));
solo.waitForDialogToClose();
onView(first(withText(R.string.queue_label))).perform(longClick());
onView(withText(R.string.downloads_label)).perform(click());
onView(withText(R.string.queue_label)).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
hidden = UserPreferences.getHiddenDrawerItems();
assertEquals(2, hidden.size());
assertTrue(hidden.contains(QueueFragment.TAG));
assertTrue(hidden.contains(PlaybackHistoryFragment.TAG));
}
@Test
public void testDrawerPreferencesHideAllElements() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
String[] titles = getInstrumentation().getTargetContext().getResources().getStringArray(R.array.nav_drawer_titles);
String[] titles = mActivityRule.getActivity().getResources().getStringArray(R.array.nav_drawer_titles);
openNavDrawer();
solo.clickLongOnText(solo.getString(R.string.queue_label));
solo.waitForDialogToOpen();
onView(first(withText(R.string.queue_label))).perform(longClick());
for (String title : titles) {
solo.clickOnText(title);
onView(first(withText(title))).perform(click());
}
solo.clickOnText(solo.getString(R.string.confirm_label));
solo.waitForDialogToClose();
onView(withText(R.string.confirm_label)).perform(click());
List<String> hidden = UserPreferences.getHiddenDrawerItems();
assertEquals(titles.length, hidden.size());
for (String tag : MainActivity.NAV_DRAWER_TAGS) {
@ -208,19 +228,17 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
}
}
@Test
public void testDrawerPreferencesHideCurrentElement() {
UserPreferences.setHiddenDrawerItems(new ArrayList<>());
openNavDrawer();
onView(withText(R.string.downloads_label)).perform(click());
openNavDrawer();
onView(first(withText(R.string.queue_label))).perform(longClick());
onView(first(withText(R.string.downloads_label))).perform(click());
onView(withText(R.string.confirm_label)).perform(click());
openNavDrawer();
String downloads = solo.getString(R.string.downloads_label);
solo.clickOnText(downloads);
solo.waitForView(android.R.id.list);
openNavDrawer();
solo.clickLongOnText(downloads);
solo.waitForDialogToOpen();
solo.clickOnText(downloads);
solo.clickOnText(solo.getString(R.string.confirm_label));
solo.waitForDialogToClose();
List<String> hidden = UserPreferences.getHiddenDrawerItems();
assertEquals(1, hidden.size());
assertTrue(hidden.contains(DownloadsFragment.TAG));

View File

@ -59,7 +59,7 @@ public class PlaybackSonicTest extends ActivityInstrumentationTestCase2<MainActi
.clear()
.putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false)
.putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false)
.putBoolean(UserPreferences.PREF_SONIC, true)
.putString(UserPreferences.PREF_MEDIA_PLAYER, "sonic")
.commit();
solo = new Solo(getInstrumentation(), getActivity());

View File

@ -1,15 +1,14 @@
package de.test.antennapod.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.test.ActivityInstrumentationTestCase2;
import android.preference.PreferenceManager;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.robotium.solo.Solo;
import com.robotium.solo.Timeout;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.PreferenceActivity;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -17,36 +16,54 @@ import de.danoeh.antennapod.core.storage.APCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
public class PreferencesTest extends ActivityInstrumentationTestCase2<PreferenceActivity> {
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
private static final String TAG = "PreferencesTest";
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
@RunWith(AndroidJUnit4.class)
public class PreferencesTest {
private Solo solo;
private Context context;
private Resources res;
private SharedPreferences prefs;
public PreferencesTest() {
super(PreferenceActivity.class);
}
@Rule
public ActivityTestRule<PreferenceActivity> mActivityRule = new ActivityTestRule<>(PreferenceActivity.class);
@Override
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
@Before
public void setUp() {
solo = new Solo(getInstrumentation(), mActivityRule.getActivity());
Timeout.setSmallTimeout(500);
Timeout.setLargeTimeout(1000);
context = getInstrumentation().getTargetContext();
res = getActivity().getResources();
UserPreferences.init(context);
res = mActivityRule.getActivity().getResources();
UserPreferences.init(mActivityRule.getActivity());
prefs = PreferenceManager.getDefaultSharedPreferences(mActivityRule.getActivity());
prefs.edit().clear();
prefs.edit().putBoolean(UserPreferences.PREF_ENABLE_AUTODL, true).commit();
}
@Override
public void tearDown() throws Exception {
@After
public void tearDown() {
solo.finishOpenedActivities();
super.tearDown();
prefs.edit().clear();
}
@Test
public void testSwitchTheme() {
final int theme = UserPreferences.getTheme();
int otherTheme;
@ -55,13 +72,13 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
} else {
otherTheme = R.string.pref_theme_title_light;
}
solo.clickOnText(solo.getString(R.string.user_interface_label));
solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(otherTheme));
clickPreference(withText(R.string.user_interface_label));
clickPreference(withText(R.string.pref_set_theme_title));
onView(withText(otherTheme)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
}
@Test
public void testSwitchThemeBack() {
final int theme = UserPreferences.getTheme();
int otherTheme;
@ -70,33 +87,23 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
} else {
otherTheme = R.string.pref_theme_title_light;
}
solo.clickOnText(solo.getString(R.string.user_interface_label));
solo.clickOnText(solo.getString(R.string.pref_set_theme_title));
solo.waitForDialogToOpen(1000);
solo.clickOnText(solo.getString(otherTheme));
clickPreference(withText(R.string.user_interface_label));
clickPreference(withText(R.string.pref_set_theme_title));
onView(withText(otherTheme)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getTheme() != theme, Timeout.getLargeTimeout()));
}
public void testExpandNotification() {
solo.clickOnText(solo.getString(R.string.user_interface_label));
final int priority = UserPreferences.getNotifyPriority();
solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
assertTrue(solo.waitForCondition(() -> priority != UserPreferences.getNotifyPriority(), Timeout.getLargeTimeout()));
solo.clickOnText(solo.getString(R.string.pref_expandNotify_title));
assertTrue(solo.waitForCondition(() -> priority == UserPreferences.getNotifyPriority(), Timeout.getLargeTimeout()));
}
@Test
public void testEnablePersistentPlaybackControls() {
solo.clickOnText(solo.getString(R.string.user_interface_label));
final boolean persistNotify = UserPreferences.isPersistNotify();
solo.scrollDown();
solo.scrollDown();
solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
clickPreference(withText(R.string.user_interface_label));
clickPreference(withText(R.string.pref_persistNotify_title));
assertTrue(solo.waitForCondition(() -> persistNotify != UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
solo.clickOnText(solo.getString(R.string.pref_persistNotify_title));
clickPreference(withText(R.string.pref_persistNotify_title));
assertTrue(solo.waitForCondition(() -> persistNotify == UserPreferences.isPersistNotify(), Timeout.getLargeTimeout()));
}
@Test
public void testSetLockscreenButtons() {
solo.clickOnText(solo.getString(R.string.user_interface_label));
solo.scrollDown();
@ -123,6 +130,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> !UserPreferences.showSkipOnCompactNotification(), Timeout.getLargeTimeout()));
}
@Test
public void testEnqueueAtFront() {
solo.clickOnText(solo.getString(R.string.playback_pref));
final boolean enqueueAtFront = UserPreferences.enqueueAtFront();
@ -134,6 +142,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> enqueueAtFront == UserPreferences.enqueueAtFront(), Timeout.getLargeTimeout()));
}
@Test
public void testHeadPhonesDisconnect() {
solo.clickOnText(solo.getString(R.string.playback_pref));
final boolean pauseOnHeadsetDisconnect = UserPreferences.isPauseOnHeadsetDisconnect();
@ -143,6 +152,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> pauseOnHeadsetDisconnect == UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout()));
}
@Test
public void testHeadPhonesReconnect() {
solo.clickOnText(solo.getString(R.string.playback_pref));
if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
@ -156,6 +166,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout()));
}
@Test
public void testBluetoothReconnect() {
solo.clickOnText(solo.getString(R.string.playback_pref));
if(UserPreferences.isPauseOnHeadsetDisconnect() == false) {
@ -169,6 +180,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> unpauseOnBluetoothReconnect == UserPreferences.isUnpauseOnBluetoothReconnect(), Timeout.getLargeTimeout()));
}
@Test
public void testContinuousPlayback() {
solo.clickOnText(solo.getString(R.string.playback_pref));
final boolean continuousPlayback = UserPreferences.isFollowQueue();
@ -180,6 +192,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> continuousPlayback == UserPreferences.isFollowQueue(), Timeout.getLargeTimeout()));
}
@Test
public void testAutoDelete() {
solo.clickOnText(solo.getString(R.string.storage_pref));
final boolean autoDelete = UserPreferences.isAutoDelete();
@ -189,17 +202,15 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> autoDelete == UserPreferences.isAutoDelete(), Timeout.getLargeTimeout()));
}
@Test
public void testPlaybackSpeeds() {
solo.clickOnText(solo.getString(R.string.playback_pref));
solo.scrollDown();
solo.scrollDown();
solo.clickOnText(solo.getString(R.string.pref_playback_speed_title));
solo.waitForDialogToOpen(1000);
clickPreference(withText(R.string.playback_pref));
clickPreference(withText(R.string.pref_playback_speed_title));
assertTrue(solo.searchText(res.getStringArray(R.array.playback_speed_values)[0]));
solo.clickOnText(solo.getString(R.string.cancel_label));
solo.waitForDialogToClose(1000);
onView(withText(R.string.cancel_label)).perform(click());
}
@Test
public void testPauseForInterruptions() {
solo.clickOnText(solo.getString(R.string.playback_pref));
final boolean pauseForFocusLoss = UserPreferences.shouldPauseForFocusLoss();
@ -209,6 +220,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> pauseForFocusLoss == UserPreferences.shouldPauseForFocusLoss(), Timeout.getLargeTimeout()));
}
@Test
public void testDisableUpdateInterval() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_sum));
@ -217,31 +229,31 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() == 0, 1000));
}
@Test
public void testSetUpdateInterval() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_title));
solo.waitForDialogToOpen();
solo.clickOnText(solo.getString(R.string.pref_autoUpdateIntervallOrTime_Interval));
solo.waitForDialogToOpen();
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_autoUpdateIntervallOrTime_title));
onView(withText(R.string.pref_autoUpdateIntervallOrTime_Interval)).perform(click());
String search = "12 " + solo.getString(R.string.pref_update_interval_hours_plural);
solo.clickOnText(search);
solo.waitForDialogToClose();
onView(withText(search)).perform(click());
assertTrue(solo.waitForCondition(() -> UserPreferences.getUpdateInterval() ==
TimeUnit.HOURS.toMillis(12), Timeout.getLargeTimeout()));
}
@Test
public void testMobileUpdates() {
solo.clickOnText(solo.getString(R.string.network_pref));
clickPreference(withText(R.string.network_pref));
final boolean mobileUpdates = UserPreferences.isAllowMobileUpdate();
solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
clickPreference(withText(R.string.pref_mobileUpdate_title));
assertTrue(solo.waitForCondition(() -> mobileUpdates != UserPreferences.isAllowMobileUpdate(), Timeout.getLargeTimeout()));
solo.clickOnText(solo.getString(R.string.pref_mobileUpdate_title));
clickPreference(withText(R.string.pref_mobileUpdate_title));
assertTrue(solo.waitForCondition(() -> mobileUpdates == UserPreferences.isAllowMobileUpdate(), Timeout.getLargeTimeout()));
}
@Test
public void testSetSequentialDownload() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_parallel_downloads_title));
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "1");
@ -249,9 +261,10 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 1, Timeout.getLargeTimeout()));
}
@Test
public void testSetParallelDownloads() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_parallel_downloads_title));
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "10");
@ -259,50 +272,50 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> UserPreferences.getParallelDownloads() == 10, Timeout.getLargeTimeout()));
}
@Test
public void testSetParallelDownloadsInvalidInput() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_parallel_downloads_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_parallel_downloads_title));
solo.waitForDialogToOpen();
solo.clearEditText(0);
solo.enterText(0, "0");
assertEquals("1", solo.getEditText(0).getText().toString());
assertEquals("", solo.getEditText(0).getText().toString());
solo.clearEditText(0);
solo.enterText(0, "100");
assertEquals("50", solo.getEditText(0).getText().toString());
assertEquals("", solo.getEditText(0).getText().toString());
}
@Test
public void testSetEpisodeCache() {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
String entry = entries[entries.length/2];
final int value = Integer.valueOf(values[values.length/2]);
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.pref_episode_cache_title));
solo.waitForDialogToOpen();
solo.clickOnText(entry);
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == value, Timeout.getLargeTimeout()));
}
@Test
public void testSetEpisodeCacheMin() {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
String minEntry = entries[0];
final int minValue = Integer.valueOf(values[0]);
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
if(!UserPreferences.isEnableAutodownload()) {
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
}
solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.pref_episode_cache_title));
solo.waitForDialogToOpen(1000);
solo.scrollUp();
solo.clickOnText(minEntry);
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == minValue, Timeout.getLargeTimeout()));
}
@Test
public void testSetEpisodeCacheMax() {
String[] entries = res.getStringArray(R.array.episode_cache_size_entries);
String[] values = res.getStringArray(R.array.episode_cache_size_values);
@ -311,24 +324,22 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
if(!UserPreferences.isEnableAutodownload()) {
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
}
solo.clickOnText(solo.getString(R.string.pref_episode_cache_title));
solo.waitForDialogToOpen();
solo.clickOnText(maxEntry);
assertTrue(solo.waitForCondition(() -> UserPreferences.getEpisodeCacheSize() == maxValue, Timeout.getLargeTimeout()));
}
@Test
public void testAutomaticDownload() {
final boolean automaticDownload = UserPreferences.isEnableAutodownload();
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.waitForText(solo.getString(R.string.pref_automatic_download_title));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.pref_automatic_download_title));
assertTrue(solo.waitForCondition(() -> automaticDownload != UserPreferences.isEnableAutodownload(), Timeout.getLargeTimeout()));
if(UserPreferences.isEnableAutodownload() == false) {
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.pref_automatic_download_title));
}
assertTrue(solo.waitForCondition(() -> UserPreferences.isEnableAutodownload() == true, Timeout.getLargeTimeout()));
final boolean enableAutodownloadOnBattery = UserPreferences.isEnableAutodownloadOnBattery();
@ -343,6 +354,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
assertTrue(solo.waitForCondition(() -> enableWifiFilter == UserPreferences.isEnableAutodownloadWifiFilter(), Timeout.getLargeTimeout()));
}
@Test
public void testEpisodeCleanupQueueOnly() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
@ -356,6 +368,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
Timeout.getLargeTimeout()));
}
@Test
public void testEpisodeCleanupNeverAlg() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
@ -369,6 +382,7 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
Timeout.getLargeTimeout()));
}
@Test
public void testEpisodeCleanupClassic() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
@ -386,12 +400,14 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
Timeout.getLargeTimeout()));
}
@Test
public void testEpisodeCleanupNumDays() {
solo.clickOnText(solo.getString(R.string.network_pref));
solo.clickOnText(solo.getString(R.string.pref_automatic_download_title));
solo.clickOnText(solo.getString(R.string.pref_episode_cleanup_title));
solo.waitForText(solo.getString(R.string.episode_cleanup_after_listening));
solo.clickOnText("5");
clickPreference(withText(R.string.network_pref));
clickPreference(withText(R.string.pref_automatic_download_title));
clickPreference(withText(R.string.pref_episode_cleanup_title));
solo.waitForDialogToOpen();
String search = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, 5, 5);
onView(withText(search)).perform(click());
assertTrue(solo.waitForCondition(() -> {
EpisodeCleanupAlgorithm alg = UserPreferences.getEpisodeCleanupAlgorithm();
if (alg instanceof APCleanupAlgorithm) {
@ -403,15 +419,13 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
Timeout.getLargeTimeout()));
}
@Test
public void testRewindChange() {
int seconds = UserPreferences.getRewindSecs();
int deltas[] = res.getIntArray(R.array.seek_delta_values);
solo.clickOnText(solo.getString(R.string.playback_pref));
solo.scrollDown();
solo.scrollDown();
solo.clickOnText(solo.getString(R.string.pref_rewind));
clickPreference(withText(R.string.playback_pref));
clickPreference(withText(R.string.pref_rewind));
solo.waitForDialogToOpen();
int currentIndex = Arrays.binarySearch(deltas, seconds);
@ -419,24 +433,22 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
// Find next value (wrapping around to next)
int newIndex = (currentIndex + 1) % deltas.length;
solo.clickOnText(String.valueOf(deltas[newIndex]) + " seconds");
solo.clickOnButton("Confirm");
onView(withText(String.valueOf(deltas[newIndex]) + " seconds")).perform(click());
onView(withText("Confirm")).perform(click());
solo.waitForDialogToClose();
assertTrue(solo.waitForCondition(() -> UserPreferences.getRewindSecs() == deltas[newIndex],
Timeout.getLargeTimeout()));
}
@Test
public void testFastForwardChange() {
solo.clickOnText(solo.getString(R.string.playback_pref));
solo.scrollDown();
solo.scrollDown();
clickPreference(withText(R.string.playback_pref));
for (int i = 2; i > 0; i--) { // repeat twice to catch any error where fastforward is tracking rewind
int seconds = UserPreferences.getFastForwardSecs();
int deltas[] = res.getIntArray(R.array.seek_delta_values);
solo.clickOnText(solo.getString(R.string.pref_fast_forward));
clickPreference(withText(R.string.pref_fast_forward));
solo.waitForDialogToOpen();
int currentIndex = Arrays.binarySearch(deltas, seconds);
@ -445,12 +457,17 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference
// Find next value (wrapping around to next)
int newIndex = (currentIndex + 1) % deltas.length;
solo.clickOnText(String.valueOf(deltas[newIndex]) + " seconds");
solo.clickOnButton("Confirm");
onView(withText(String.valueOf(deltas[newIndex]) + " seconds")).perform(click());
onView(withText("Confirm")).perform(click());
solo.waitForDialogToClose();
assertTrue(solo.waitForCondition(() -> UserPreferences.getFastForwardSecs() == deltas[newIndex],
Timeout.getLargeTimeout()));
}
}
private void clickPreference(Matcher<View> matcher) {
onView(withId(R.id.list))
.perform(RecyclerViewActions.actionOnItem(hasDescendant(matcher), click()));
}
}

View File

@ -42,7 +42,7 @@ project.ext {
minSdkVersion = 14
targetSdkVersion = 26
supportVersion = "26.1.0"
supportVersion = "27.1.1"
awaitilityVersion = "3.1.2"
commonsioVersion = "2.5"
commonslangVersion = "3.6"

View File

@ -10,7 +10,7 @@ android {
versionCode 1
versionName "1.0"
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "de.danoeh.antennapod.core.AntennaPodTestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
@ -83,6 +83,9 @@ dependencies {
}
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}

View File

@ -1,16 +0,0 @@
package de.danoeh.antennapod.core;
import android.test.InstrumentationTestRunner;
import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.TestSuite;
public class AntennaPodTestRunner extends InstrumentationTestRunner {
@Override
public TestSuite getAllTests() {
return new TestSuiteBuilder(AntennaPodTestRunner.class)
.includeAllPackagesUnderHere()
.build();
}
}