Skip to content

Commit 8081789

Browse files
committed
Migrate Android Tests to Unit Tests
1 parent 950ce8f commit 8081789

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
@@ -157,6 +157,7 @@ jobs:
157157
android-tests:
158158
name: Android Tests
159159
runs-on: ubuntu-latest
160+
if: ${{ false }} # TODO Remove this line if/when we have Android Tests
160161
needs: build
161162
env:
162163
USERNAME: ${{ github.actor }}

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ androidx-paging = "3.2.1"
1515
androidx-test-core = "1.5.0"
1616
androidx-test-ext-junit = "1.1.5"
1717
androidx-test-monitor = "1.6.1"
18-
androidx-test-runner = "1.5.2"
1918
androidx-tv-foundation = "1.0.0-alpha10"
2019
androidx-tv-material = "1.0.0-beta01"
2120
coil = "2.6.0"
@@ -61,7 +60,6 @@ androidx-paging-common = { module = "androidx.paging:paging-common", version.ref
6160
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" }
6261
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" }
6362
androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" }
64-
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
6563
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv-foundation" }
6664
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
6765
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 {
@@ -54,14 +44,8 @@ dependencies {
5444
testImplementation(libs.kotlinx.coroutines.test)
5545
testImplementation(libs.mockk)
5646
testImplementation(libs.mockk.dsl)
57-
testRuntimeOnly(libs.robolectric)
47+
testImplementation(libs.robolectric)
5848
testImplementation(libs.robolectric.annotations)
5949
testImplementation(libs.robolectric.shadows.framework)
6050
testImplementation(libs.turbine)
61-
62-
androidTestImplementation(libs.androidx.test.monitor)
63-
androidTestRuntimeOnly(libs.androidx.test.runner)
64-
androidTestImplementation(libs.junit)
65-
androidTestRuntimeOnly(libs.kotlinx.coroutines.android)
66-
androidTestImplementation(libs.mockk)
6751
}

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://swi-vod.akamaized.net/videoJson/47603186/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)