Skip to content

Commit bb8d123

Browse files
authored
Merge pull request #37 from TeamNewPipe/test_rig
Test rig
2 parents 8c5de94 + 847e404 commit bb8d123

File tree

5 files changed

+67
-30
lines changed

5 files changed

+67
-30
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref
7373
androidx-hilt-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltCompiler" }
7474
androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigationCompose" }
7575
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hiltAndroid" }
76+
hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hiltAndroid"}
7677
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
7778
androidx-foundation = { group = "androidx.compose.foundation", name = "foundation", version.ref = "uiTooling" }
7879
androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "fragmentKtx" }
@@ -96,6 +97,7 @@ dokka-android = {module = "org.jetbrains.dokka:android-documentation-plugin", ve
9697
newplayer = { group = "com.github.theScrabi.NewPlayer", name = "new-player", version.ref = "newplayer" }
9798

9899

100+
99101
[plugins]
100102
android-application = { id = "com.android.application", version.ref = "agp" }
101103
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

test-app/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ android {
5555
versionCode = 1
5656
versionName = "1.0"
5757

58-
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
58+
testInstrumentationRunner = "net.newpipe.newplayer.testapp.HiltTestRunner"
5959
vectorDrawables {
6060
useSupportLibrary = true
6161
}
@@ -116,6 +116,8 @@ dependencies {
116116

117117
// development impl
118118
implementation(project(":new-player"))
119+
androidTestImplementation(libs.hilt.android.testing)
120+
kspAndroidTest(libs.hilt.android.compiler)
119121
//jitpack test
120122
//implementation(libs.newplayer)
121123

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.newpipe.newplayer.testapp
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import androidx.test.runner.AndroidJUnitRunner
6+
import dagger.hilt.android.testing.HiltTestApplication
7+
8+
class HiltTestRunner : AndroidJUnitRunner() {
9+
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
10+
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
11+
}
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package net.newpipe.newplayer.testapp
2+
3+
import androidx.compose.ui.test.ExperimentalTestApi
4+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
5+
import androidx.test.espresso.Espresso.onView
6+
import androidx.test.espresso.action.ViewActions
7+
import androidx.test.espresso.matcher.ViewMatchers
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import androidx.test.platform.app.InstrumentationRegistry
10+
import dagger.hilt.android.testing.HiltAndroidRule
11+
import dagger.hilt.android.testing.HiltAndroidTest
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
@HiltAndroidTest
18+
class SmokeTest {
19+
@get:Rule(order = 0)
20+
val hiltRule = HiltAndroidRule(this)
21+
22+
@get:Rule(order = 1)
23+
val composeTestRule = createAndroidComposeRule<MainActivity>()
24+
25+
@Test
26+
fun smokeTest() {
27+
onView(ViewMatchers.withText("Start 6502 Stream")).perform(ViewActions.click())
28+
}
29+
30+
@OptIn(ExperimentalTestApi::class)
31+
@Test
32+
fun checkNewPlayerIsPlayingTest() {
33+
onView(ViewMatchers.withText("Start 6502 Stream")).perform(ViewActions.click())
34+
35+
composeTestRule.waitUntil(timeoutMillis = 5000) {
36+
var isPlaying = false
37+
InstrumentationRegistry.getInstrumentation().runOnMainSync {
38+
isPlaying = composeTestRule.activity.newPlayer.exoPlayer.value?.isPlaying ?: false
39+
}
40+
isPlaying
41+
}
42+
43+
// catuall test
44+
var isPlaying = false
45+
InstrumentationRegistry.getInstrumentation().runOnMainSync {
46+
isPlaying = composeTestRule.activity.newPlayer.exoPlayer.value?.isPlaying ?: false
47+
}
48+
assert(isPlaying)
49+
}
50+
}

test-app/src/androidTest/java/net/newpipe/newplayer/testapp/TestTest.kt

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

0 commit comments

Comments
 (0)