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 Apr 3, 2024
1 parent e35933d commit e256dbd
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 143 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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 build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ dependencyAnalysis {
onUnusedDependencies {
// These dependencies are not used directly, but automatically used by libs.androidx.media3.exoplayer
exclude(libs.androidx.media3.dash, libs.androidx.media3.hls)
// This dependency is used automatically by libs.mockk
exclude(libs.mockk.android)
}
}

Expand Down
3 changes: 0 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ androidx-paging = "3.2.1"
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 = "1.0.0-alpha10"
coil = "2.6.0"
comscore = "6.10.0"
Expand Down Expand Up @@ -60,7 +59,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" }
androidx-tv-material = { module = "androidx.tv:tv-material", version.ref = "androidx-tv" }
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
Expand Down Expand Up @@ -89,7 +87,6 @@ detekt-cli = { group = "io.gitlab.arturbosch.detekt", name = "detekt-cli", versi
detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
mockk-android = { group = "io.mockk", name = "mockk-android", version.ref = "mockk" }
mockk-dsl = { group = "io.mockk", name = "mockk-dsl-jvm", version.ref = "mockk" }
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
Expand Down
19 changes: 1 addition & 18 deletions pillarbox-player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,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 @@ -51,15 +41,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)
androidTestImplementation(libs.mockk.android)
}

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: PillarboxPlayer

@BeforeTest
fun setUp() {
player = PillarboxPlayer(
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://swi-vod.akamaized.net/videoJson/47603186/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 e256dbd

Please sign in to comment.