Skip to content

Commit

Permalink
Migrate Android Tests to Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Jun 26, 2024
1 parent 641dae4 commit f58eb65
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 139 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ jobs:
android-tests:
name: Android Tests
runs-on: ubuntu-latest
if: ${{ false }} # TODO Remove this line if/when we have Android Tests
needs: build
env:
USERNAME: ${{ github.actor }}
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ androidx-paging = "3.3.0"
androidx-test-core = "1.5.0"
androidx-test-ext-junit = "1.1.5"
androidx-test-monitor = "1.6.1"
androidx-test-runner = "1.5.2"
androidx-tv-foundation = "1.0.0-alpha10"
androidx-tv-material = "1.0.0-beta01"
coil = "2.6.0"
Expand Down Expand Up @@ -63,7 +62,6 @@ androidx-paging-common = { module = "androidx.paging:paging-common", version.ref
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" }
androidx-test-monitor = { module = "androidx.test:monitor", version.ref = "androidx-test-monitor" }
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" }
androidx-tv-foundation = { module = "androidx.tv:tv-foundation", version.ref = "androidx-tv-foundation" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv-material" }
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
Expand Down
18 changes: 1 addition & 17 deletions pillarbox-player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ android {
buildFeatures {
buildConfig = true
}

// Mockk includes some licenses information, which may conflict with other license files. This block merges all licenses together.
// Mockk excludes all licenses instead:
// https://github.com/mockk/mockk/blob/f879502a044c83c2a5fd52992f20903209eb34f3/modules/mockk-android/build.gradle.kts#L14-L19
packaging {
resources {
merges += "META-INF/LICENSE.md"
merges += "META-INF/LICENSE-notice.md"
}
}
}

dependencies {
Expand Down Expand Up @@ -54,14 +44,8 @@ dependencies {
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.mockk)
testImplementation(libs.mockk.dsl)
testRuntimeOnly(libs.robolectric)
testImplementation(libs.robolectric)
testImplementation(libs.robolectric.annotations)
testImplementation(libs.robolectric.shadows.framework)
testImplementation(libs.turbine)

androidTestImplementation(libs.androidx.test.monitor)
androidTestRuntimeOnly(libs.androidx.test.runner)
androidTestImplementation(libs.junit)
androidTestRuntimeOnly(libs.kotlinx.coroutines.android)
androidTestImplementation(libs.mockk)
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.player

import android.net.Uri
import android.os.Looper
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.test.utils.FakeClock
import androidx.media3.test.utils.robolectric.TestPlayerRunHelper
import androidx.test.core.app.ApplicationProvider
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
import org.robolectric.Shadows.shadowOf
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

@RunWith(ParameterizedRobolectricTestRunner::class)
class IsPlayingAllTypeOfContentTest(
private val urlToTest: String
) {
private lateinit var player: PillarboxExoPlayer

@BeforeTest
fun setUp() {
player = PillarboxExoPlayer(
context = ApplicationProvider.getApplicationContext(),
clock = FakeClock(true),
)
}

@AfterTest
fun tearDown() {
player.release()

shadowOf(Looper.getMainLooper()).idle()
}

@Test
fun `is playing`() {
player.addMediaItem(MediaItem.fromUri(urlToTest))
player.prepare()
player.play()

TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY)

// Make test flaky because dependant of internet
if (player.playerError != null) {
throw IllegalStateException(player.playerError)
}

assertEquals(Player.STATE_READY, player.playbackState)
assertTrue(player.isPlaying)
assertNotNull(player.currentMediaItem)
assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest))
}

companion object {
// From urn:swi:video:48940210
private const val VOD_MP4 =
"https://cdn.prod.swi-services.ch/video-projects/141b30ce-3850-424b-9063-a20d5619d342/localised-videos/ENG/renditions/ENG.mp4"
private const val VOD_HLS = "https://rts-vod-amd.akamaized.net/ww/14970442/7510ee63-05a4-3d48-8d26-1f1b3a82f6be/master.m3u8"
private const val AOD_MP3 = "https://srfaudio-a.akamaihd.net/delivery/world/af671f12-6f17-415a-9dd8-b8aee24cce8b.mp3"
private const val VOD_DASH_H264 = "https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd"
private const val VOD_DASH_H265 = "https://storage.googleapis.com/wvmedia/clear/hevc/tears/tears.mpd"
private const val LIVE_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8?dw=0"
private const val LIVE_DVR_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8"
private const val AUDIO_LIVE_MP3 = "https://stream.srg-ssr.ch/m/la-1ere/mp3_128"
private const val AUDIO_LIVE_DVR_HLS = "https://lsaplus.swisstxt.ch/audio/couleur3_96.stream/playlist.m3u8"

@JvmStatic
@Suppress("unused")
@Parameters(name = "{index}: {0}")
fun parameters(): Iterable<Any> {
return listOf(
VOD_MP4,
VOD_HLS,
AOD_MP3,
VOD_DASH_H264,
VOD_DASH_H265,
LIVE_HLS,
LIVE_DVR_HLS,
AUDIO_LIVE_MP3,
AUDIO_LIVE_DVR_HLS,
)
}
}
}

0 comments on commit f58eb65

Please sign in to comment.