Replaced inheritance with parameterized test

This commit is contained in:
ByteHamster 2019-12-02 10:06:16 +01:00
parent e77ecda206
commit a9987aeaa6
4 changed files with 18 additions and 53 deletions

View File

@ -1,17 +0,0 @@
package de.test.antennapod.playback;
import androidx.test.filters.LargeTest;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import org.junit.Before;
/**
* Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity.
*/
@LargeTest
public class PlaybackBuiltinTest extends PlaybackTest {
@Before
public void setUp() throws Exception {
super.setUp();
UserPreferences.enableBuiltin();
}
}

View File

@ -1,17 +0,0 @@
package de.test.antennapod.playback;
import androidx.test.filters.LargeTest;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import org.junit.Before;
/**
* Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity.
*/
@LargeTest
public class PlaybackExoplayerTest extends PlaybackTest {
@Before
public void setUp() throws Exception {
super.setUp();
UserPreferences.enableExoplayer();
}
}

View File

@ -1,17 +0,0 @@
package de.test.antennapod.playback;
import androidx.test.filters.LargeTest;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import org.junit.Before;
/**
* Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity.
*/
@LargeTest
public class PlaybackSonicTest extends PlaybackTest {
@Before
public void setUp() throws Exception {
super.setUp();
UserPreferences.enableSonic();
}
}

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import de.danoeh.antennapod.R;
@ -21,7 +22,11 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -45,14 +50,22 @@ import static org.junit.Assert.assertTrue;
/**
* Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity.
*/
public abstract class PlaybackTest {
@LargeTest
@RunWith(Parameterized.class)
public class PlaybackTest {
@Rule
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class, false, false);
@Parameterized.Parameter(value = 0)
public String playerToUse;
private UITestUtils uiTestUtils;
protected Context context;
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> initParameters() {
return Arrays.asList(new Object[][] { { "exoplayer" }, { "builtin" }, { "sonic" } });
}
@Before
public void setUp() throws Exception {
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
@ -60,6 +73,9 @@ public abstract class PlaybackTest {
EspressoTestUtils.clearDatabase();
EspressoTestUtils.makeNotFirstRun();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putString(UserPreferences.PREF_MEDIA_PLAYER, playerToUse).apply();
uiTestUtils = new UITestUtils(context);
uiTestUtils.setup();
}