[ADD] Tests LoginVM

Android
Renaud BEURET 1 year ago
parent ac75980226
commit 34d852acb1

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="ModuleClassLoaderOverlays">
<paths>
<option value="/tmp/overlay16255881331565398814" />
<option value="/tmp/overlay3325279776421233033" />
</paths>
</component>
</module>

@ -67,8 +67,8 @@ dependencies {
implementation("androidx.compose.material3:material3")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
testImplementation("junit:junit:4.13.2")
testImplementation("io.mockk:mockk:1.13.10")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))

@ -1,17 +0,0 @@
package fr.iut.sciencequest
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}

@ -0,0 +1,51 @@
package fr.iut.sciencequest.viewModel
import fr.iut.sciencequest.testRules.MainDispatcherRule
import fr.iut.sciencequest.viewModels.LoginViewModel
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
class LoginViewModelTest(
val exempleString: String
) {
@get:Rule
val mainDispatcherRule = MainDispatcherRule()
@Test
fun setMdpTest() {
val viewModel = LoginViewModel()
viewModel.setMdp(exempleString)
Assert.assertEquals(exempleString, viewModel.uiState.value.mdp)
}
@Test
fun setPseudoTest() {
val viewModel = LoginViewModel()
viewModel.setPseudo(exempleString)
Assert.assertEquals(exempleString, viewModel.uiState.value.pseudo)
}
companion object {
@JvmStatic
@Parameterized.Parameters(
name = "Quand joueur joue {0}, le jeu est censé trouvé que {1} est {3} et il lui reste {2} "
)
fun getTestActionData(): Iterable<Array<Any>> {
return arrayListOf(
arrayOf("Jean"),
arrayOf("jean"),
arrayOf("Jean2"),
arrayOf("jean2"),
arrayOf("jean_"),
arrayOf("jean+"),
)
}
}
}

@ -16,6 +16,7 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import kotlin.concurrent.thread
import kotlin.time.Duration
class KahootLancerPartieTest {
@ -25,6 +26,10 @@ class KahootLancerPartieTest {
@Before
fun setup() {
}
@Test
fun KahootLancerPartieTest() = runTest (timeout = Duration.parse("15s")) {
mockkStatic(Looper::class)
val looper = mockk<Looper> {
@ -32,10 +37,6 @@ class KahootLancerPartieTest {
}
every { Looper.getMainLooper() } returns looper
}
@Test
fun KahootLancerPartieTest() = runTest (timeout = Duration.parse("15s")) {
val question = StubQuestionWithReponses.ToModel()
val repo = QuestionStubRepository()
repo.setQuestionsStub(arrayListOf(

Loading…
Cancel
Save