Skip to content

Commit ca81ab4

Browse files
committed
Migrate Android Tests to Unit Tests
1 parent 07ff076 commit ca81ab4

File tree

6 files changed

+97
-139
lines changed

6 files changed

+97
-139
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ jobs:
159159
android-tests:
160160
name: Android Tests
161161
runs-on: ubuntu-latest
162+
if: ${{ false }} # TODO Remove this line if/when we have Android Tests
162163
needs: build
163164
env:
164165
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.0"
1313
androidx-test-core = "1.6.1"
1414
androidx-test-ext-junit = "1.2.1"
1515
androidx-test-monitor = "1.7.1"
16-
androidx-test-runner = "1.6.1"
1716
androidx-tv-foundation = "1.0.0-alpha10"
1817
androidx-tv-material = "1.0.0-beta01"
1918
coil = "2.7.0"
@@ -58,7 +57,6 @@ androidx-paging-common = { module = "androidx.paging:paging-common", version.ref
5857
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" }
5958
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" }
6059
androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" }
61-
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
6260
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv-foundation" }
6361
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
6462
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }

pillarbox-player/build.gradle.kts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ android {
1414
buildFeatures {
1515
buildConfig = true
1616
}
17-
18-
// Mockk includes some licenses information, which may conflict with other license files. This block merges all licenses together.
19-
// Mockk excludes all licenses instead:
20-
// https://github.com/mockk/mockk/blob/f879502a044c83c2a5fd52992f20903209eb34f3/modules/mockk-android/build.gradle.kts#L14-L19
21-
packaging {
22-
resources {
23-
merges += "META-INF/LICENSE.md"
24-
merges += "META-INF/LICENSE-notice.md"
25-
}
26-
}
2717
}
2818

2919
dependencies {
@@ -53,14 +43,8 @@ dependencies {
5343
testImplementation(libs.kotlinx.coroutines.test)
5444
testImplementation(libs.mockk)
5545
testImplementation(libs.mockk.dsl)
56-
testRuntimeOnly(libs.robolectric)
46+
testImplementation(libs.robolectric)
5747
testImplementation(libs.robolectric.annotations)
5848
testImplementation(libs.robolectric.shadows.framework)
5949
testImplementation(libs.turbine)
60-
61-
androidTestImplementation(libs.androidx.test.monitor)
62-
androidTestRuntimeOnly(libs.androidx.test.runner)
63-
androidTestImplementation(libs.junit)
64-
androidTestRuntimeOnly(libs.kotlinx.coroutines.android)
65-
androidTestImplementation(libs.mockk)
6650
}

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 & 18 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
clock = FakeClock(true),
36+
)
37+
}
38+
39+
@AfterTest
40+
fun tearDown() {
41+
player.release()
42+
43+
shadowOf(Looper.getMainLooper()).idle()
44+
}
45+
46+
@Test
47+
fun `is playing`() {
48+
player.addMediaItem(MediaItem.fromUri(urlToTest))
49+
player.prepare()
50+
player.play()
51+
52+
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)
53+
54+
// Make test flaky because dependant of internet
55+
if (player.playerError != null) {
56+
throw IllegalStateException(player.playerError)
57+
}
58+
59+
assertEquals(Player.STATE_READY, player.playbackState)
60+
assertTrue(player.isPlaying)
61+
assertNotNull(player.currentMediaItem)
62+
assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest))
63+
}
64+
65+
companion object {
66+
// From urn:swi:video:48940210
67+
private const val VOD_MP4 =
68+
"https://cdn.prod.swi-services.ch/video-projects/141b30ce-3850-424b-9063-a20d5619d342/localised-videos/ENG/renditions/ENG.mp4"
69+
private const val VOD_HLS = "https://rts-vod-amd.akamaized.net/ww/14970442/7510ee63-05a4-3d48-8d26-1f1b3a82f6be/master.m3u8"
70+
private const val AOD_MP3 = "https://srfaudio-a.akamaihd.net/delivery/world/af671f12-6f17-415a-9dd8-b8aee24cce8b.mp3"
71+
private const val VOD_DASH_H264 = "https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd"
72+
private const val VOD_DASH_H265 = "https://storage.googleapis.com/wvmedia/clear/hevc/tears/tears.mpd"
73+
private const val LIVE_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8?dw=0"
74+
private const val LIVE_DVR_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8"
75+
private const val AUDIO_LIVE_MP3 = "https://stream.srg-ssr.ch/m/la-1ere/mp3_128"
76+
private const val AUDIO_LIVE_DVR_HLS = "https://lsaplus.swisstxt.ch/audio/couleur3_96.stream/playlist.m3u8"
77+
78+
@JvmStatic
79+
@Suppress("unused")
80+
@Parameters(name = "{index}: {0}")
81+
fun parameters(): Iterable<Any> {
82+
return listOf(
83+
VOD_MP4,
84+
VOD_HLS,
85+
AOD_MP3,
86+
VOD_DASH_H264,
87+
VOD_DASH_H265,
88+
LIVE_HLS,
89+
LIVE_DVR_HLS,
90+
AUDIO_LIVE_MP3,
91+
AUDIO_LIVE_DVR_HLS,
92+
)
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)