Skip to content

Commit 0788058

Browse files
committed
Migrate Android Tests to Unit Tests
1 parent 353ee5f commit 0788058

File tree

6 files changed

+99
-141
lines changed

6 files changed

+99
-141
lines changed

.github/workflows/quality.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ jobs:
167167
android-tests:
168168
name: Android Tests
169169
runs-on: ubuntu-latest
170+
if: ${{ false }} # TODO Remove this line if/when we have Android Tests
170171
needs: build
171172
env:
172173
USERNAME: ${{ github.actor }}

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ androidx-paging = "3.3.5"
1313
androidx-test-core = "1.6.1"
1414
androidx-test-ext-junit = "1.2.1"
1515
androidx-test-monitor = "1.7.2"
16-
androidx-test-runner = "1.6.2"
1716
androidx-tv-material = "1.0.0"
1817
coil = "3.0.4"
1918
comscore = "6.11.1"
@@ -60,7 +59,6 @@ androidx-paging-common = { module = "androidx.paging:paging-common", version.ref
6059
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" }
6160
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" }
6261
androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" }
63-
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
6462
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
6563
coil = { group = "io.coil-kt.coil3", name = "coil", version.ref = "coil" }
6664
coil-compose = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" }

pillarbox-player/build.gradle.kts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ android {
1919
buildFeatures {
2020
buildConfig = true
2121
}
22-
23-
// Mockk includes some licenses information, which may conflict with other license files. This block merges all licenses together.
24-
// Mockk excludes all licenses instead:
25-
// https://github.com/mockk/mockk/blob/f879502a044c83c2a5fd52992f20903209eb34f3/modules/mockk-android/build.gradle.kts#L14-L19
26-
packaging {
27-
resources {
28-
merges += "META-INF/LICENSE.md"
29-
merges += "META-INF/LICENSE-notice.md"
30-
}
31-
}
3222
}
3323

3424
dependencies {
@@ -64,15 +54,8 @@ dependencies {
6454
testImplementation(libs.mockk)
6555
testImplementation(libs.mockk.dsl)
6656
testImplementation(libs.okio)
67-
testRuntimeOnly(libs.robolectric)
57+
testImplementation(libs.robolectric)
6858
testImplementation(libs.robolectric.annotations)
6959
testImplementation(libs.robolectric.shadows.framework)
7060
testImplementation(libs.turbine)
71-
72-
androidTestImplementation(libs.androidx.test.monitor)
73-
androidTestRuntimeOnly(libs.androidx.test.runner)
74-
androidTestImplementation(libs.junit)
75-
androidTestImplementation(libs.kotlin.test)
76-
androidTestRuntimeOnly(libs.kotlinx.coroutines.android)
77-
androidTestImplementation(libs.mockk)
7861
}

pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/IsPlayingAllTypeOfContentTest.kt

Lines changed: 0 additions & 102 deletions
This file was deleted.

pillarbox-player/src/androidTest/java/ch/srgssr/pillarbox/player/utils/ContentUrls.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) SRG SSR. All rights reserved.
3+
* License information is available from the LICENSE file.
4+
*/
5+
package ch.srgssr.pillarbox.player
6+
7+
import android.net.Uri
8+
import android.os.Looper
9+
import androidx.media3.common.MediaItem
10+
import androidx.media3.common.Player
11+
import androidx.media3.test.utils.FakeClock
12+
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
13+
import androidx.test.core.app.ApplicationProvider
14+
import org.junit.runner.RunWith
15+
import org.robolectric.ParameterizedRobolectricTestRunner
16+
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
17+
import org.robolectric.Shadows.shadowOf
18+
import kotlin.test.AfterTest
19+
import kotlin.test.BeforeTest
20+
import kotlin.test.Test
21+
import kotlin.test.assertEquals
22+
import kotlin.test.assertNotNull
23+
import kotlin.test.assertTrue
24+
25+
@RunWith(ParameterizedRobolectricTestRunner::class)
26+
class IsPlayingAllTypeOfContentTest(
27+
private val urlToTest: String
28+
) {
29+
private lateinit var player: PillarboxExoPlayer
30+
31+
@BeforeTest
32+
fun setUp() {
33+
player = PillarboxExoPlayer(
34+
context = ApplicationProvider.getApplicationContext(),
35+
type = Default,
36+
) {
37+
clock(FakeClock(true))
38+
}
39+
}
40+
41+
@AfterTest
42+
fun tearDown() {
43+
player.release()
44+
45+
shadowOf(Looper.getMainLooper()).idle()
46+
}
47+
48+
@Test
49+
fun `is playing`() {
50+
player.addMediaItem(MediaItem.fromUri(urlToTest))
51+
player.prepare()
52+
player.play()
53+
54+
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
55+
56+
// Make test flaky because dependant of internet
57+
if (player.playerError != null) {
58+
throw IllegalStateException(player.playerError)
59+
}
60+
61+
assertEquals(Player.STATE_READY, player.playbackState)
62+
assertTrue(player.isPlaying)
63+
assertNotNull(player.currentMediaItem)
64+
assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest))
65+
}
66+
67+
companion object {
68+
// From urn:swi:video:48940210
69+
private const val VOD_MP4 =
70+
"https://cdn.prod.swi-services.ch/video-projects/141b30ce-3850-424b-9063-a20d5619d342/localised-videos/ENG/renditions/ENG.mp4"
71+
private const val VOD_HLS = "https://rts-vod-amd.akamaized.net/ww/14970442/da2b38fb-ca9f-3c76-80c6-e6fa7f3c2699/master.m3u8"
72+
private const val AOD_MP3 = "https://srfaudio-a.akamaihd.net/delivery/world/af671f12-6f17-415a-9dd8-b8aee24cce8b.mp3"
73+
private const val VOD_DASH_H264 = "https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd"
74+
private const val VOD_DASH_H265 = "https://storage.googleapis.com/wvmedia/clear/hevc/tears/tears.mpd"
75+
private const val LIVE_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8?dw=0"
76+
private const val LIVE_DVR_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8"
77+
private const val AUDIO_LIVE_MP3 = "https://stream.srg-ssr.ch/m/la-1ere/mp3_128"
78+
private const val AUDIO_LIVE_DVR_HLS = "https://lsaplus.swisstxt.ch/audio/couleur3_96.stream/playlist.m3u8"
79+
80+
@JvmStatic
81+
@Suppress("unused")
82+
@Parameters(name = "{index}: {0}")
83+
fun parameters(): Iterable<Any> {
84+
return listOf(
85+
VOD_MP4,
86+
VOD_HLS,
87+
AOD_MP3,
88+
VOD_DASH_H264,
89+
VOD_DASH_H265,
90+
LIVE_HLS,
91+
LIVE_DVR_HLS,
92+
AUDIO_LIVE_MP3,
93+
AUDIO_LIVE_DVR_HLS,
94+
)
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)